2019-09-03 08:34:02 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2019-09-24 14:40:01 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2020-02-07 19:25:38 +01:00
|
|
|
import com.simibubi.create.config.AllConfigs;
|
2019-09-24 14:40:01 +02:00
|
|
|
import com.simibubi.create.modules.curiosities.partialWindows.WindowInABlockTileEntity;
|
|
|
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.block.FourWayBlock;
|
|
|
|
import net.minecraft.block.WallBlock;
|
|
|
|
import net.minecraft.item.BlockItem;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.state.BooleanProperty;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraft.world.IWorld;
|
2019-09-24 14:40:01 +02:00
|
|
|
import net.minecraft.world.World;
|
2020-03-21 18:32:53 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
2019-09-24 14:40:01 +02:00
|
|
|
import net.minecraftforge.common.Tags;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.event.TickEvent.Phase;
|
|
|
|
import net.minecraftforge.event.TickEvent.ServerTickEvent;
|
2019-09-24 14:40:01 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraftforge.event.world.WorldEvent;
|
2019-09-24 14:40:01 +02:00
|
|
|
import net.minecraftforge.eventbus.api.Event.Result;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2020-03-21 18:32:53 +01:00
|
|
|
import net.minecraftforge.fml.DistExecutor;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
|
|
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
|
|
|
|
|
|
|
@EventBusSubscriber
|
|
|
|
public class Events {
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onTick(ServerTickEvent event) {
|
2019-12-15 01:13:36 +01:00
|
|
|
if (event.phase == Phase.END)
|
2019-09-03 08:34:02 +02:00
|
|
|
return;
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
Create.tick();
|
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onClose(FMLServerStoppingEvent event) {
|
|
|
|
Create.shutdown();
|
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-09-03 23:03:52 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onLoadWorld(WorldEvent.Load event) {
|
|
|
|
IWorld world = event.getWorld();
|
2020-01-05 19:41:38 +01:00
|
|
|
Create.redstoneLinkNetworkHandler.onLoadWorld(world);
|
2019-11-01 01:09:38 +01:00
|
|
|
Create.torquePropagator.onLoadWorld(world);
|
2020-03-21 18:32:53 +01:00
|
|
|
if (event.getWorld().isRemote())
|
|
|
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> CreateClient.bufferCache::invalidate);
|
2019-09-03 23:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onUnloadWorld(WorldEvent.Unload event) {
|
|
|
|
IWorld world = event.getWorld();
|
2020-01-05 19:41:38 +01:00
|
|
|
Create.redstoneLinkNetworkHandler.onUnloadWorld(world);
|
2019-11-01 01:09:38 +01:00
|
|
|
Create.torquePropagator.onUnloadWorld(world);
|
2019-09-03 23:03:52 +02:00
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onRightClickBlock(RightClickBlock event) {
|
|
|
|
if (event.getUseItem() == Result.DENY)
|
|
|
|
return;
|
|
|
|
if (event.getEntityLiving().isSneaking())
|
|
|
|
return;
|
|
|
|
if (!event.getPlayer().isAllowEdit())
|
|
|
|
return;
|
2020-02-07 19:25:38 +01:00
|
|
|
if (!AllConfigs.SERVER.curiosities.allowGlassPanesInPartialBlocks.get())
|
2019-09-24 14:40:01 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
ItemStack stack = event.getItemStack();
|
|
|
|
if (stack.isEmpty())
|
|
|
|
return;
|
|
|
|
if (!(stack.getItem() instanceof BlockItem))
|
|
|
|
return;
|
2020-02-27 18:09:41 +01:00
|
|
|
BlockItem item = (BlockItem) stack.getItem();
|
|
|
|
if (!item.isIn(Tags.Items.GLASS_PANES)
|
|
|
|
&& (item.getBlock() == null || !item.getBlock().isIn(Tags.Blocks.GLASS_PANES)))
|
|
|
|
return;
|
2019-09-24 14:40:01 +02:00
|
|
|
|
|
|
|
BlockPos pos = event.getPos();
|
|
|
|
World world = event.getWorld();
|
|
|
|
BlockState blockState = world.getBlockState(pos);
|
|
|
|
if (!AllBlockTags.WINDOWABLE.matches(blockState))
|
|
|
|
return;
|
|
|
|
if (AllBlocks.WINDOW_IN_A_BLOCK.typeOf(blockState))
|
|
|
|
return;
|
|
|
|
|
2019-10-05 19:00:43 +02:00
|
|
|
BlockState defaultState = AllBlocks.WINDOW_IN_A_BLOCK.get().getDefaultState();
|
|
|
|
world.setBlockState(pos, defaultState);
|
2019-09-24 14:40:01 +02:00
|
|
|
TileEntity te = world.getTileEntity(pos);
|
|
|
|
if (te != null && te instanceof WindowInABlockTileEntity) {
|
|
|
|
WindowInABlockTileEntity wte = (WindowInABlockTileEntity) te;
|
2020-02-27 18:09:41 +01:00
|
|
|
wte.setWindowBlock(item.getBlock().getDefaultState());
|
2019-09-24 14:40:01 +02:00
|
|
|
wte.updateWindowConnections();
|
|
|
|
|
|
|
|
if (blockState.getBlock() instanceof FourWayBlock) {
|
|
|
|
for (BooleanProperty side : Arrays.asList(FourWayBlock.EAST, FourWayBlock.NORTH, FourWayBlock.SOUTH,
|
|
|
|
FourWayBlock.WEST))
|
|
|
|
blockState = blockState.with(side, false);
|
|
|
|
}
|
|
|
|
if (blockState.getBlock() instanceof WallBlock)
|
|
|
|
blockState = blockState.with(WallBlock.UP, true);
|
|
|
|
|
|
|
|
wte.setPartialBlock(blockState);
|
|
|
|
wte.requestModelDataUpdate();
|
|
|
|
|
|
|
|
if (!event.getPlayer().isCreative())
|
|
|
|
stack.shrink(1);
|
|
|
|
event.getPlayer().swingArm(event.getHand());
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|