This commit is contained in:
parent
e599ad409c
commit
6d8839d5ab
5 changed files with 87 additions and 2 deletions
20
src/main/java/net/pietru/cookie_utils/api/Area.java
Normal file
20
src/main/java/net/pietru/cookie_utils/api/Area.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package net.pietru.cookie_utils.api;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||
|
||||
public class Area {
|
||||
BoundingBox space = new BoundingBox();
|
||||
|
||||
public BoundingBox getBox() {
|
||||
return space;
|
||||
}
|
||||
|
||||
public void setCorners(Vector3 a, Vector3 b){
|
||||
space.set(a,b);
|
||||
}
|
||||
|
||||
public boolean does_intersect(Vector3 c){
|
||||
return space.contains(c);
|
||||
}
|
||||
}
|
26
src/main/java/net/pietru/cookie_utils/api/Region.java
Normal file
26
src/main/java/net/pietru/cookie_utils/api/Region.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package net.pietru.cookie_utils.api;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import finalforeach.cosmicreach.blocks.BlockPosition;
|
||||
import finalforeach.cosmicreach.world.Zone;
|
||||
|
||||
public class Region {
|
||||
|
||||
public static Array<Area> areas = new Array<>();
|
||||
|
||||
public static boolean can_edit_block(BlockPosition position){
|
||||
Zone z = position.getZone();
|
||||
Vector3 g_position = new Vector3(position.getGlobalX(),position.getGlobalY(),position.getGlobalZ());
|
||||
boolean can = true;
|
||||
|
||||
for (Area a : areas){
|
||||
if (a.does_intersect(g_position)){
|
||||
can=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return can;
|
||||
}
|
||||
}
|
|
@ -14,6 +14,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.can_edit_block;
|
||||
|
||||
@Mixin(BreakBlockPacket.class)
|
||||
public class BlockBreakMixin {
|
||||
@Shadow
|
||||
|
@ -26,7 +28,7 @@ public class BlockBreakMixin {
|
|||
@Inject(method = "handle", at = @At("HEAD"), cancellable = true)
|
||||
private void event_block_break(@Local NetworkIdentity identity, @Local ChannelHandlerContext ctx, CallbackInfo ci){
|
||||
if (identity.getSide() != NetworkSide.CLIENT) {
|
||||
if (this.blockPos.getBlockState() == this.brokenBlockState) {
|
||||
if (!can_edit_block(blockPos)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package net.pietru.cookie_utils.mixins;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import finalforeach.cosmicreach.blocks.BlockPosition;
|
||||
import finalforeach.cosmicreach.blocks.BlockState;
|
||||
import finalforeach.cosmicreach.networking.common.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.common.NetworkSide;
|
||||
import finalforeach.cosmicreach.networking.netty.packets.blocks.PlaceBlockPacket;
|
||||
import finalforeach.cosmicreach.world.Zone;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.can_edit_block;
|
||||
|
||||
@Mixin(PlaceBlockPacket.class)
|
||||
public class BlockPlaceMixin {
|
||||
@Shadow
|
||||
Zone zone;
|
||||
@Shadow
|
||||
BlockPosition blockPos;
|
||||
@Shadow
|
||||
BlockState targetBlockState;
|
||||
|
||||
@Inject(method = "handle", at = @At("HEAD"), cancellable = true)
|
||||
private void event_block_place(@Local NetworkIdentity identity, @Local ChannelHandlerContext ctx, CallbackInfo ci){
|
||||
if (identity.getSide() != NetworkSide.CLIENT) {
|
||||
if (!can_edit_block(blockPos)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,8 @@
|
|||
"package": "net.pietru.cookie_utils.mixins",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"BlockBreakMixin"
|
||||
"BlockBreakMixin",
|
||||
"BlockPlaceMixin"
|
||||
],
|
||||
"client": [],
|
||||
"injectors": {
|
||||
|
|
Loading…
Reference in a new issue