water protection and piston protection (that was hell)
This commit is contained in:
parent
3220e064ed
commit
ba95c9a3d7
@ -3,8 +3,13 @@ package com.flemmli97.flan.event;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
@ -22,4 +27,41 @@ public class WorldEvents {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean pistonCanPush(BlockState state, World world, BlockPos blockPos, Direction direction, Direction pistonDir){
|
||||
if(world.isClient||direction == Direction.UP || direction == Direction.DOWN)
|
||||
return true;
|
||||
boolean empty = state.isAir() || state.getPistonBehavior() == PistonBehavior.DESTROY;
|
||||
BlockPos dirPos = blockPos.offset(direction);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim from = storage.getClaimAt(blockPos);
|
||||
Claim to = storage.getClaimAt(dirPos);
|
||||
boolean flag = true;
|
||||
if(!empty){
|
||||
if((from!=null && !from.equals(to)) || (from==null && to!=null))
|
||||
flag = false;
|
||||
}
|
||||
if(from!=null && from.equals(to)){
|
||||
Claim opp = storage.getClaimAt(blockPos.offset(direction.getOpposite()));
|
||||
flag = from.equals(opp);
|
||||
}
|
||||
if(!flag) {
|
||||
world.updateListeners(blockPos, state, state, 20);
|
||||
BlockState toState = world.getBlockState(dirPos);
|
||||
world.updateListeners(dirPos, toState, toState, 20);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static boolean canFlow(BlockState fluidBlockState, BlockView world, BlockPos blockPos, Direction direction){
|
||||
if(!(world instanceof ServerWorld)||direction == Direction.UP || direction == Direction.DOWN)
|
||||
return true;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim from = storage.getClaimAt(blockPos);
|
||||
Claim to = storage.getClaimAt(blockPos.offset(direction));
|
||||
boolean fl = from == null && to == null;
|
||||
if(from!=null)
|
||||
fl = from.equals(to);
|
||||
return fl;
|
||||
}
|
||||
}
|
||||
|
27
src/main/java/com/flemmli97/flan/mixin/FluidMixin.java
Normal file
27
src/main/java/com/flemmli97/flan/mixin/FluidMixin.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.flemmli97.flan.mixin;
|
||||
|
||||
import com.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.fluid.FlowableFluid;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(FlowableFluid.class)
|
||||
public abstract class FluidMixin {
|
||||
|
||||
@Inject(method = "canFlow", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void crossClaimFlow(BlockView world, BlockPos fluidPos, BlockState fluidBlockState, Direction flowDirection, BlockPos flowTo,
|
||||
BlockState flowToBlockState, FluidState fluidState, Fluid fluid, CallbackInfoReturnable<Boolean> info){
|
||||
if(!WorldEvents.canFlow(fluidBlockState, world, fluidPos, flowDirection)){
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
25
src/main/java/com/flemmli97/flan/mixin/PistonMixin.java
Normal file
25
src/main/java/com/flemmli97/flan/mixin/PistonMixin.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.flemmli97.flan.mixin;
|
||||
|
||||
import com.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.PistonBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(PistonBlock.class)
|
||||
public class PistonMixin {
|
||||
|
||||
@Inject(method = "isMovable", at = @At(value = "HEAD"), cancellable = true)
|
||||
private static void checkMovable(BlockState blockState, World world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info){
|
||||
if(!WorldEvents.pistonCanPush(blockState, world, blockPos, direction, pistonDir)) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,9 @@
|
||||
"IPersistentProjectileVars",
|
||||
"LivingEntityMixin",
|
||||
"ItemStackMixin",
|
||||
"ILecternBlockValues"
|
||||
"ILecternBlockValues",
|
||||
"FluidMixin",
|
||||
"PistonMixin"
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user