diff --git a/README.md b/README.md index 45518b1..3afa07e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The tex * Read config (see "Config elements" below) ### TODO +* DROP UPGRADES WHEN SCREEN IS DESTROYED * Achievements (minePad 2 and all that stuff) +* Top/bottom screen orientation * GuiSetURL2 missing buttons * Plugin API * Automatically add protocol to URLs diff --git a/src/main/java/net/montoyo/wd/WebDisplays.java b/src/main/java/net/montoyo/wd/WebDisplays.java index 272f183..bbcf48a 100644 --- a/src/main/java/net/montoyo/wd/WebDisplays.java +++ b/src/main/java/net/montoyo/wd/WebDisplays.java @@ -59,9 +59,12 @@ public class WebDisplays { public Item itemStoneKey; public ItemMinePad2 itemMinePad; public ItemUpgrade itemUpgrade; + public ItemLaserPointer itemLaserPointer; //Sounds public SoundEvent soundTyping; + public SoundEvent soundUpgradeAdd; + public SoundEvent soundUpgradeDel; //Config public static final double PAD_RATIO = 59.0 / 30.0; @@ -94,6 +97,7 @@ public class WebDisplays { itemLinker = new ItemLinker(); itemMinePad = new ItemMinePad2(); itemUpgrade = new ItemUpgrade(); + itemLaserPointer = new ItemLaserPointer(); itemStoneKey = new Item(); itemStoneKey.setCreativeTab(CREATIVE_TAB); @@ -132,14 +136,21 @@ public class WebDisplays { @SubscribeEvent public void onRegisterItems(RegistryEvent.Register ev) { ev.getRegistry().registerAll(blockScreen.getItem(), blockPeripheral.getItem()); - ev.getRegistry().registerAll(itemScreenCfg, itemOwnerThief, itemLinker, itemStoneKey, itemMinePad, itemUpgrade); + ev.getRegistry().registerAll(itemScreenCfg, itemOwnerThief, itemLinker, itemStoneKey, itemMinePad, itemUpgrade, itemLaserPointer); } @SubscribeEvent public void onRegisterSounds(RegistryEvent.Register ev) { soundTyping = new SoundEvent(new ResourceLocation("webdisplays", "keyboardType")); soundTyping.setRegistryName(soundTyping.getSoundName()); - ev.getRegistry().register(soundTyping); + + soundUpgradeAdd = new SoundEvent(new ResourceLocation("webdisplays", "upgradeAdd")); + soundUpgradeAdd.setRegistryName(soundUpgradeAdd.getSoundName()); + + soundUpgradeDel = new SoundEvent(new ResourceLocation("webdisplays", "upgradeDel")); + soundUpgradeDel.setRegistryName(soundUpgradeDel.getSoundName()); + + ev.getRegistry().registerAll(soundTyping, soundUpgradeAdd, soundUpgradeDel); } @SubscribeEvent diff --git a/src/main/java/net/montoyo/wd/block/BlockScreen.java b/src/main/java/net/montoyo/wd/block/BlockScreen.java index 8250224..8fd0565 100644 --- a/src/main/java/net/montoyo/wd/block/BlockScreen.java +++ b/src/main/java/net/montoyo/wd/block/BlockScreen.java @@ -136,7 +136,7 @@ public class BlockScreen extends WDBlockContainer { return true; } - if(te.addUpgrade(side, heldItem, false)) { + if(te.addUpgrade(side, heldItem, player, false)) { if(!player.isCreative()) heldItem.shrink(1); diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index d5cc1b0..d16fbf5 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -263,6 +263,7 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi registerItemModel(wd.itemLinker, 0, "normal"); registerItemModel(wd.itemStoneKey, 0, "normal"); registerItemModel(wd.itemMinePad, 0, "normal"); + registerItemModel(wd.itemLaserPointer, 0, "normal"); DefaultUpgrade[] upgrades = DefaultUpgrade.values(); for(int i = 0; i < upgrades.length; i++) diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java b/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java index 38051bf..1da6e5c 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java @@ -415,6 +415,9 @@ public class GuiScreenConfig extends WDScreen { if(flag) btnSetRes.setDisabled(true); + + flag = (myRights & ScreenRights.MANAGE_UPGRADES) == 0; + ugUpgrades.setDisabled(flag); } public void updateResolution(Vector2i res) { diff --git a/src/main/java/net/montoyo/wd/client/gui/controls/UpgradeGroup.java b/src/main/java/net/montoyo/wd/client/gui/controls/UpgradeGroup.java index 1a2ae42..408e937 100644 --- a/src/main/java/net/montoyo/wd/client/gui/controls/UpgradeGroup.java +++ b/src/main/java/net/montoyo/wd/client/gui/controls/UpgradeGroup.java @@ -31,7 +31,7 @@ public class UpgradeGroup extends BasicControl { int x = this.x; for(ItemStack is: upgrades) { - if(is == overStack) + if(is == overStack && !disabled) fillRect(x, y, 16, 16, 0x80FF0000); renderItem.renderItemAndEffectIntoGUI(mc.player, is, x, y); @@ -104,7 +104,7 @@ public class UpgradeGroup extends BasicControl { @Override public void mouseReleased(int mouseX, int mouseY, int state) { if(state == 0 && clickStack != null) { - if(clickStack == overStack && upgrades.contains(clickStack)) //HOTFIX: Make sure it's actually in the list :p + if(clickStack == overStack && !disabled && upgrades.contains(clickStack)) //HOTFIX: Make sure it's actually in the list :p parent.actionPerformed(new ClickEvent(this)); clickStack = null; diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java index 3ea5198..e18c232 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java @@ -4,6 +4,7 @@ package net.montoyo.wd.entity; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -12,6 +13,7 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvent; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.common.network.NetworkRegistry; @@ -28,7 +30,6 @@ import net.montoyo.wd.utilities.*; import javax.annotation.Nullable; import java.util.*; -import java.util.function.Predicate; public class TileEntityScreen extends TileEntity { @@ -548,16 +549,19 @@ public class TileEntityScreen extends TileEntity { } else { WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.type(this, side, text), point()); - if(soundPos != null) { - double x = (double) soundPos.getX(); - double y = (double) soundPos.getY(); - double z = (double) soundPos.getZ(); - - world.playSound(null, x + 0.5, y + 0.5, z + 0.5, WebDisplays.INSTANCE.soundTyping, SoundCategory.BLOCKS, 0.25f, 1.f); - } + if(soundPos != null) + playSoundAt(WebDisplays.INSTANCE.soundTyping, soundPos, 0.25f, 1.f); } } + private void playSoundAt(SoundEvent snd, BlockPos at, float vol, float pitch) { + double x = (double) at.getX(); + double y = (double) at.getY(); + double z = (double) at.getZ(); + + world.playSound(null, x + 0.5, y + 0.5, z + 0.5, snd, SoundCategory.BLOCKS, vol, pitch); + } + public void updateUpgrades(BlockSide side, ItemStack[] upgrades) { if(!world.isRemote) { Log.error("Tried to call TileEntityScreen.updateUpgrades() from server side..."); @@ -580,7 +584,7 @@ public class TileEntityScreen extends TileEntity { } //If equal is null, no duplicate check is preformed - public boolean addUpgrade(BlockSide side, ItemStack is, boolean abortIfExisting) { + public boolean addUpgrade(BlockSide side, ItemStack is, @Nullable EntityPlayer player, boolean abortIfExisting) { if(world.isRemote) return false; @@ -606,7 +610,8 @@ public class TileEntityScreen extends TileEntity { scr.upgrades.add(is); WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.upgrade(this, side), point()); - itemAsUpgrade.onInstall(this, side, null, is); + itemAsUpgrade.onInstall(this, side, player, is); + playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, pos, 1.0f, 1.0f); return true; } @@ -623,7 +628,7 @@ public class TileEntityScreen extends TileEntity { return scr.upgrades.stream().anyMatch((otherStack) -> itemAsUpgrade.isSameUpgrade(is, otherStack)); } - public void removeUpgrade(BlockSide side, ItemStack is) { + public void removeUpgrade(BlockSide side, ItemStack is, @Nullable EntityPlayer player) { if(world.isRemote) return; @@ -649,8 +654,26 @@ public class TileEntityScreen extends TileEntity { } if(idxToRemove >= 0) { + if(!itemAsUpgrade.onRemove(this, side, player, scr.upgrades.get(idxToRemove))) { //Drop upgrade item + ItemStack toDrop = scr.upgrades.get(idxToRemove); + boolean spawnDrop = true; + + if(player != null) { + if(player.isCreative() || player.addItemStackToInventory(toDrop)) + spawnDrop = false; //If in creative or if the item was added to the player's inventory, don't spawn drop entity + } + + if(spawnDrop) { + Vector3f pos = new Vector3f((float) this.pos.getX(), (float) this.pos.getY(), (float) this.pos.getZ()); + pos.addMul(side.backward.toFloat(), 1.5f); + + world.spawnEntity(new EntityItem(world, (double) pos.x, (double) pos.y, (double) pos.z, toDrop)); + } + } + scr.upgrades.remove(idxToRemove); WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.upgrade(this, side), point()); + playSoundAt(WebDisplays.INSTANCE.soundUpgradeDel, pos, 1.0f, 1.0f); } else Log.warning("Tried to remove non-existing upgrade %s to screen %s at %s", safeName(is), side.toString(), pos.toString()); } diff --git a/src/main/java/net/montoyo/wd/item/ItemLaserPointer.java b/src/main/java/net/montoyo/wd/item/ItemLaserPointer.java new file mode 100644 index 0000000..ca02d85 --- /dev/null +++ b/src/main/java/net/montoyo/wd/item/ItemLaserPointer.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2018 BARBOTIN Nicolas + */ + +package net.montoyo.wd.item; + +import net.minecraft.item.Item; +import net.montoyo.wd.WebDisplays; + +public class ItemLaserPointer extends Item { + + public ItemLaserPointer() { + setUnlocalizedName("webdisplays.laserpointer"); + setRegistryName("laserpointer"); + setMaxStackSize(1); + setCreativeTab(WebDisplays.CREATIVE_TAB); + } + +} diff --git a/src/main/java/net/montoyo/wd/net/SMessageScreenCtrl.java b/src/main/java/net/montoyo/wd/net/SMessageScreenCtrl.java index 179db62..63b6182 100644 --- a/src/main/java/net/montoyo/wd/net/SMessageScreenCtrl.java +++ b/src/main/java/net/montoyo/wd/net/SMessageScreenCtrl.java @@ -220,7 +220,7 @@ public class SMessageScreenCtrl implements IMessage, Runnable { tes.type(side, text, soundPos); } else if(ctrl == CTRL_REMOVE_UPGRADE) { checkPermission(tes, ScreenRights.MANAGE_UPGRADES); - tes.removeUpgrade(side, toRemove); + tes.removeUpgrade(side, toRemove, player); } else Log.info("SMessageScreenCtrl: TODO"); //TODO: other ctrl messages } diff --git a/src/main/resources/assets/webdisplays/models/item/laserpointer.json b/src/main/resources/assets/webdisplays/models/item/laserpointer.json new file mode 100644 index 0000000..b6b74c0 --- /dev/null +++ b/src/main/resources/assets/webdisplays/models/item/laserpointer.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "webdisplays:items/laserpointer" + } +} diff --git a/src/main/resources/assets/webdisplays/models/item/upgrade_lasermouse.json b/src/main/resources/assets/webdisplays/models/item/upgrade_lasermouse.json index 26bc6f7..0d70e0c 100644 --- a/src/main/resources/assets/webdisplays/models/item/upgrade_lasermouse.json +++ b/src/main/resources/assets/webdisplays/models/item/upgrade_lasermouse.json @@ -2,6 +2,6 @@ "parent": "item/generated", "textures": { "layer0": "webdisplays:items/upgrade", - "layer1": "webdisplays:items/laserpointer" + "layer1": "webdisplays:items/laserpointer2" } } diff --git a/src/main/resources/assets/webdisplays/sounds.json b/src/main/resources/assets/webdisplays/sounds.json index 217cbca..7558e4e 100644 --- a/src/main/resources/assets/webdisplays/sounds.json +++ b/src/main/resources/assets/webdisplays/sounds.json @@ -1,16 +1,30 @@ { - "keyboardType": { - "category": "block", - "subtitle": "block.webdisplays.keyboard", - "sounds": [ - "webdisplays:keyboard1", - "webdisplays:keyboard2", - "webdisplays:keyboard3", - "webdisplays:keyboard4", - "webdisplays:keyboard5", - "webdisplays:keyboard6", - "webdisplays:keyboard7", - "webdisplays:keyboard8" - ] - } + "keyboardType": { + "category": "block", + "subtitle": "block.webdisplays.keyboard", + "sounds": [ + "webdisplays:keyboard1", + "webdisplays:keyboard2", + "webdisplays:keyboard3", + "webdisplays:keyboard4", + "webdisplays:keyboard5", + "webdisplays:keyboard6", + "webdisplays:keyboard7", + "webdisplays:keyboard8" + ] + }, + "upgradeAdd": { + "category": "block", + "subtitle": "block.webdisplays.upgradeAdd", + "sounds": [ + "webdisplays:upgrade_add" + ] + }, + "upgradeDel": { + "category": "block", + "subtitle": "block.webdisplays.upgradeDel", + "sounds": [ + "webdisplays:upgrade_del" + ] + } } diff --git a/src/main/resources/assets/webdisplays/sounds/upgrade_add.ogg b/src/main/resources/assets/webdisplays/sounds/upgrade_add.ogg new file mode 100644 index 0000000..6885234 Binary files /dev/null and b/src/main/resources/assets/webdisplays/sounds/upgrade_add.ogg differ diff --git a/src/main/resources/assets/webdisplays/sounds/upgrade_del.ogg b/src/main/resources/assets/webdisplays/sounds/upgrade_del.ogg new file mode 100644 index 0000000..304393f Binary files /dev/null and b/src/main/resources/assets/webdisplays/sounds/upgrade_del.ogg differ diff --git a/src/main/resources/assets/webdisplays/textures/items/laserpointer.png b/src/main/resources/assets/webdisplays/textures/items/laserpointer.png index 13f915b..64bf7da 100644 Binary files a/src/main/resources/assets/webdisplays/textures/items/laserpointer.png and b/src/main/resources/assets/webdisplays/textures/items/laserpointer.png differ diff --git a/src/main/resources/assets/webdisplays/textures/items/laserpointer2.png b/src/main/resources/assets/webdisplays/textures/items/laserpointer2.png index 64bf7da..13f915b 100644 Binary files a/src/main/resources/assets/webdisplays/textures/items/laserpointer2.png and b/src/main/resources/assets/webdisplays/textures/items/laserpointer2.png differ