diff --git a/src/main/java/net/montoyo/wd/WebDisplays.java b/src/main/java/net/montoyo/wd/WebDisplays.java index 7c245a9..f9bf292 100644 --- a/src/main/java/net/montoyo/wd/WebDisplays.java +++ b/src/main/java/net/montoyo/wd/WebDisplays.java @@ -7,6 +7,7 @@ package net.montoyo.wd; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.SoundEvents; import net.minecraft.item.Item; @@ -20,6 +21,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.Loader; @@ -86,6 +88,7 @@ public class WebDisplays { public SoundEvent soundUpgradeDel; public SoundEvent soundScreenCfg; public SoundEvent soundServer; + public SoundEvent soundIronic; //Criterions public Criterion criterionPadBreak; @@ -234,6 +237,7 @@ public class WebDisplays { soundUpgradeDel = registerSound(ev, "upgradeDel"); soundScreenCfg = registerSound(ev, "screencfgOpen"); soundServer = registerSound(ev, "server"); + soundIronic = registerSound(ev, "ironic"); } @SubscribeEvent @@ -337,6 +341,23 @@ public class WebDisplays { Server.getInstance().getClientManager().revokeClientKey(ev.player.getGameProfile().getId()); } + @SubscribeEvent + public void onChat(ServerChatEvent ev) { + String msg = ev.getMessage().trim().replaceAll("\\s+", " ").toLowerCase(); + StringBuilder sb = new StringBuilder(msg.length()); + for(int i = 0; i < msg.length(); i++) { + char chr = msg.charAt(i); + + if(chr != '.' && chr != ',' && chr != ';' && chr != '!' && chr != '?' && chr != ':' && chr != '\'' && chr != '\"' && chr != '`') + sb.append(chr); + } + + if(sb.toString().equals("ironic he could save others from death but not himself")) { + EntityPlayer ply = ev.getPlayer(); + ply.world.playSound(null, ply.posX, ply.posY, ply.posZ, soundIronic, SoundCategory.PLAYERS, 1.0f, 1.0f); + } + } + private boolean hasPlayerAdvancement(EntityPlayerMP ply, ResourceLocation rl) { MinecraftServer server = PROXY.getServer(); if(server == null) diff --git a/src/main/java/net/montoyo/wd/block/BlockScreen.java b/src/main/java/net/montoyo/wd/block/BlockScreen.java index 58cac43..87cac9d 100644 --- a/src/main/java/net/montoyo/wd/block/BlockScreen.java +++ b/src/main/java/net/montoyo/wd/block/BlockScreen.java @@ -37,6 +37,7 @@ import net.montoyo.wd.data.SetURLData; import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.utilities.*; +import javax.annotation.Nonnull; import javax.annotation.Nullable; public class BlockScreen extends WDBlockContainer { @@ -50,10 +51,10 @@ public class BlockScreen extends WDBlockContainer { sideFlags[i] = Properties.toUnlisted(PropertyInteger.create("neighbor" + i, 0, 15)); } - public static final int BAR_BOT = 1; - public static final int BAR_RIGHT = 2; - public static final int BAR_TOP = 4; - public static final int BAR_LEFT = 8; + private static final int BAR_BOT = 1; + private static final int BAR_RIGHT = 2; + private static final int BAR_TOP = 4; + private static final int BAR_LEFT = 8; public BlockScreen() { super(Material.ROCK); @@ -64,11 +65,13 @@ public class BlockScreen extends WDBlockContainer { } @Override + @Nonnull public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } @Override + @Nonnull protected BlockStateContainer createBlockState() { return new ExtendedBlockState(this, properties, sideFlags); } @@ -78,7 +81,8 @@ public class BlockScreen extends WDBlockContainer { } @Override - public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos bpos) { + @Nonnull + public IBlockState getExtendedState(@Nonnull IBlockState state, IBlockAccess world, BlockPos bpos) { IExtendedBlockState ret = (IExtendedBlockState) blockState.getBaseState(); Vector3i pos = new Vector3i(bpos); @@ -96,6 +100,7 @@ public class BlockScreen extends WDBlockContainer { } @Override + @Nonnull public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(hasTE, (meta & 1) != 0).withProperty(emitting, (meta & 2) != 0); } @@ -277,7 +282,10 @@ public class BlockScreen extends WDBlockContainer { @Nullable @Override - public TileEntity createNewTileEntity(World world, int meta) { + public TileEntity createNewTileEntity(@Nonnull World world, int meta) { + if((meta & 1) == 0) + return null; + return ((meta & 1) == 0) ? null : new TileEntityScreen(); } @@ -305,7 +313,7 @@ public class BlockScreen extends WDBlockContainer { } @Override - public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer ply, boolean willHarvest) { + public boolean removedByPlayer(@Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer ply, boolean willHarvest) { onDestroy(world, pos, ply); return super.removedByPlayer(state, world, pos, ply, willHarvest); } @@ -339,6 +347,7 @@ public class BlockScreen extends WDBlockContainer { } @Override + @Nonnull public EnumPushReaction getMobilityFlag(IBlockState state) { return EnumPushReaction.IGNORE; } diff --git a/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java b/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java index e1b7a0c..159b6f3 100644 --- a/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java +++ b/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java @@ -13,6 +13,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import net.montoyo.mcef.api.IBrowser; import net.montoyo.mcef.api.IJSQueryCallback; import net.montoyo.wd.WebDisplays; +import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.core.DefaultUpgrade; import net.montoyo.wd.core.IScreenQueryHandler; import net.montoyo.wd.core.IUpgrade; @@ -239,7 +240,8 @@ public final class JSQueryDispatcher { if(x < 0 || x >= scr.size.x || y < 0 || y >= scr.size.y) cb.failure(403, "Out of range"); else { - int level = tes.getWorld().getRedstonePower((new Vector3i(tes.getPos())).addMul(side.right, x).addMul(side.up, y).toBlock(), EnumFacing.VALUES[side.reverse().ordinal()]); + BlockPos bpos = (new Vector3i(tes.getPos())).addMul(side.right, x).addMul(side.up, y).toBlock(); + int level = tes.getWorld().getBlockState(bpos).getValue(BlockScreen.emitting) ? 0 : tes.getWorld().getRedstonePower(bpos, EnumFacing.VALUES[side.reverse().ordinal()]); cb.success("{\"level\":" + level + "}"); } } else @@ -263,7 +265,12 @@ public final class JSQueryDispatcher { resp.append(','); vec2.toBlock(mbp); - resp.append(tes.getWorld().getRedstonePower(mbp, facing)); + + if(tes.getWorld().getBlockState(mbp).getValue(BlockScreen.emitting)) + resp.append(0); + else + resp.append(tes.getWorld().getRedstonePower(mbp, facing)); + vec2.add(side.right.x, side.right.y, side.right.z); } diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java index 28859e8..762c8f6 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java @@ -33,6 +33,7 @@ import net.montoyo.wd.net.server.SMessageRequestTEData; import net.montoyo.wd.utilities.*; import net.montoyo.wd.utilities.Rotation; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.*; @@ -179,7 +180,12 @@ public class TileEntityScreen extends TileEntity { for(int x = 0; x < size.x; x++) { vec2.toBlock(mbp); - redstoneStatus.set(base + x, world.getRedstonePower(mbp, facing)); + + if(world.getBlockState(mbp).getValue(BlockScreen.emitting)) + redstoneStatus.set(base + x, 0); + else + redstoneStatus.set(base + x, world.getRedstonePower(mbp, facing)); + vec2.add(side.right.x, side.right.y, side.right.z); } @@ -241,6 +247,7 @@ public class TileEntityScreen extends TileEntity { } @Override + @Nonnull public NBTTagCompound writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); @@ -252,7 +259,7 @@ public class TileEntityScreen extends TileEntity { return tag; } - public NetworkRegistry.TargetPoint point() { + private NetworkRegistry.TargetPoint point() { return new NetworkRegistry.TargetPoint(world.provider.getDimension(), (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 64.0); } @@ -633,6 +640,7 @@ public class TileEntityScreen extends TileEntity { } @Override + @Nonnull public AxisAlignedBB getRenderBoundingBox() { return renderBB; } @@ -871,10 +879,7 @@ public class TileEntityScreen extends TileEntity { public boolean hasUpgrade(BlockSide side, DefaultUpgrade du) { Screen scr = getScreen(side); - if(scr == null) - return false; - - return scr.upgrades.stream().anyMatch(du::matches); + return scr != null && scr.upgrades.stream().anyMatch(du::matches); } public void removeUpgrade(BlockSide side, ItemStack is, @Nullable EntityPlayer player) { @@ -1052,4 +1057,9 @@ public class TileEntityScreen extends TileEntity { WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.js(this, side, code), point()); } + @Override + public boolean shouldRefresh(World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState) { + return oldState.getValue(BlockScreen.hasTE) != newState.getValue(BlockScreen.hasTE); + } + } diff --git a/src/main/resources/assets/webdisplays/sounds.json b/src/main/resources/assets/webdisplays/sounds.json index 68c0910..70fea52 100644 --- a/src/main/resources/assets/webdisplays/sounds.json +++ b/src/main/resources/assets/webdisplays/sounds.json @@ -35,5 +35,11 @@ "sounds": [ "webdisplays:server" ] + }, + "ironic": { + "category": "player", + "sounds": [ + "webdisplays:ironic" + ] } } diff --git a/src/main/resources/assets/webdisplays/sounds/ironic.ogg b/src/main/resources/assets/webdisplays/sounds/ironic.ogg new file mode 100644 index 0000000..bcbe3a9 Binary files /dev/null and b/src/main/resources/assets/webdisplays/sounds/ironic.ogg differ