forge: fix piston protection close #134

This commit is contained in:
Flemmli97 2022-02-07 12:24:53 +01:00
parent b70246e1d4
commit 282faa82e0
6 changed files with 9 additions and 15 deletions

View File

@ -30,7 +30,7 @@ public class WorldEvents {
}
public static boolean pistonCanPush(BlockState state, Level world, BlockPos blockPos, Direction direction, Direction pistonDir) {
if (world.isClientSide || state.isAir())
if (world.isClientSide)
return true;
BlockPos dirPos = blockPos.relative(direction);
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
@ -42,7 +42,7 @@ public class WorldEvents {
IPermissionContainer opp = storage.getForPermissionCheck(oppPoos);
if (!from.equals(opp))
flag = from.canInteract(null, PermissionRegistry.PISTONBORDER, oppPoos);
} else
} else if (!state.isAir())
flag = from.canInteract(null, PermissionRegistry.PISTONBORDER, blockPos) && to.canInteract(null, PermissionRegistry.PISTONBORDER, dirPos);
if (!flag) {
//Idk enough about piston behaviour to update more blocks when slime is involved.

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.fabric.mixin;
package io.github.flemmli97.flan.mixin;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.core.BlockPos;
@ -14,6 +14,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(PistonBaseBlock.class)
public abstract class PistonMixin {
/**
* Forge does have an event for piston interaction but the location of the event makes it not really applicable
* for this usecase. Would need to calculate all the affected blocks (specially in case of slime contraptions)
*/
@Inject(method = "isPushable", at = @At(value = "HEAD"), cancellable = true)
private static void checkMovable(BlockState blockState, Level world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info) {
if (!WorldEvents.pistonCanPush(blockState, world, blockPos, direction, pistonDir)) {

View File

@ -24,7 +24,8 @@
"LightningFireEntityMixin",
"BannedEntryAccessor",
"MinecraftServerMixin",
"AbstractContainerAccessor"
"AbstractContainerAccessor",
"PistonMixin"
],
"server": [
],

View File

@ -5,7 +5,6 @@
"compatibilityLevel": "JAVA_16",
"mixins": [
"ServerWorldMixin",
"PistonMixin",
"SpawnHelperMixin",
"PlayerInteractEntityMixin",
"ProjectileMixin",

View File

@ -25,7 +25,6 @@ public class FlanForge {
IEventBus forge = MinecraftForge.EVENT_BUS;
forge.addListener(WorldEventsForge::modifyExplosion);
forge.addListener(WorldEventsForge::pistonCanPush);
forge.addListener(WorldEventsForge::preventMobSpawn);
forge.addListener(ItemInteractEventsForge::useItem);
forge.addListener(BlockInteractEventsForge::startBreakBlocks);

View File

@ -3,10 +3,8 @@ package io.github.flemmli97.flan.forgeevent;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.Level;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.event.world.PistonEvent;
import net.minecraftforge.eventbus.api.Event;
public class WorldEventsForge {
@ -16,13 +14,6 @@ public class WorldEventsForge {
WorldEvents.modifyExplosion(event.getExplosion(), (ServerLevel) event.getWorld());
}
public static void pistonCanPush(PistonEvent.Pre event) {
if (!(event.getWorld() instanceof Level))
return;
if (!WorldEvents.pistonCanPush(event.getState(), (Level) event.getWorld(), event.getPos(), event.getDirection(), event.getDirection()))
event.setCanceled(true);
}
public static void preventMobSpawn(LivingSpawnEvent.CheckSpawn event) {
if (!(event.getWorld() instanceof ServerLevel) || !(event.getEntityLiving() instanceof Mob))
return;