* More work on upgrades
This commit is contained in:
parent
614411eeb6
commit
c6d0f4f183
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<Item> 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<SoundEvent> 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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
19
src/main/java/net/montoyo/wd/item/ItemLaserPointer.java
Normal file
19
src/main/java/net/montoyo/wd/item/ItemLaserPointer.java
Normal file
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "webdisplays:items/laserpointer"
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,6 @@
|
|||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "webdisplays:items/upgrade",
|
||||
"layer1": "webdisplays:items/laserpointer"
|
||||
"layer1": "webdisplays:items/laserpointer2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
src/main/resources/assets/webdisplays/sounds/upgrade_add.ogg
Normal file
BIN
src/main/resources/assets/webdisplays/sounds/upgrade_add.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/webdisplays/sounds/upgrade_del.ogg
Normal file
BIN
src/main/resources/assets/webdisplays/sounds/upgrade_del.ogg
Normal file
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 368 B |
Binary file not shown.
|
Before Width: | Height: | Size: 368 B After Width: | Height: | Size: 268 B |
Loading…
Reference in New Issue
Block a user