more refactoring
This commit is contained in:
parent
55be33ac44
commit
be68ca40f0
|
|
@ -142,8 +142,6 @@ public class WebDisplays {
|
||||||
onRegisterSounds();
|
onRegisterSounds();
|
||||||
BlockInit.init(bus);
|
BlockInit.init(bus);
|
||||||
ItemInit.init(bus);
|
ItemInit.init(bus);
|
||||||
ItemInit.registerUpgrade();
|
|
||||||
ItemInit.registerComponents();
|
|
||||||
TileInit.init(bus);
|
TileInit.init(bus);
|
||||||
|
|
||||||
PROXY.preInit();
|
PROXY.preInit();
|
||||||
|
|
@ -264,7 +262,7 @@ public class WebDisplays {
|
||||||
if(!ev.getEntity().getLevel().isClientSide) {
|
if(!ev.getEntity().getLevel().isClientSide) {
|
||||||
ItemStack is = ev.getEntity().getItem();
|
ItemStack is = ev.getEntity().getItem();
|
||||||
|
|
||||||
if(is.getItem() == ItemInit.itemMinePad.get()) {
|
if(is.getItem() == ItemInit.MINEPAD.get()) {
|
||||||
CompoundTag tag = is.getTag();
|
CompoundTag tag = is.getTag();
|
||||||
|
|
||||||
if(tag == null) {
|
if(tag == null) {
|
||||||
|
|
@ -282,7 +280,7 @@ public class WebDisplays {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onPlayerCraft(PlayerEvent.ItemCraftedEvent ev) {
|
public void onPlayerCraft(PlayerEvent.ItemCraftedEvent ev) {
|
||||||
if(CommonConfig.hardRecipes && ev.getCrafting().getItem() == ItemInit.itemCraftComp.get() && (CraftComponent.EXTCARD.makeItemStack().is(ev.getCrafting().getItem()))) {
|
if(CommonConfig.hardRecipes && ItemInit.isCompCraftItem(ev.getCrafting().getItem()) && (CraftComponent.EXTCARD.makeItemStack().is(ev.getCrafting().getItem()))) {
|
||||||
if((ev.getEntity() instanceof ServerPlayer && !hasPlayerAdvancement((ServerPlayer) ev.getEntity(), ADV_PAD_BREAK)) || PROXY.hasClientPlayerAdvancement(ADV_PAD_BREAK) != HasAdvancement.YES) {
|
if((ev.getEntity() instanceof ServerPlayer && !hasPlayerAdvancement((ServerPlayer) ev.getEntity(), ADV_PAD_BREAK)) || PROXY.hasClientPlayerAdvancement(ADV_PAD_BREAK) != HasAdvancement.YES) {
|
||||||
ev.getCrafting().setDamageValue(CraftComponent.BADEXTCARD.ordinal());
|
ev.getCrafting().setDamageValue(CraftComponent.BADEXTCARD.ordinal());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -758,10 +758,10 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
||||||
Item item = ev.getItemStack().getItem();
|
Item item = ev.getItemStack().getItem();
|
||||||
IItemRenderer renderer;
|
IItemRenderer renderer;
|
||||||
|
|
||||||
if(ItemInit.itemMinePad.isPresent() && ItemInit.itemLaserPointer.isPresent()) {
|
if(ItemInit.MINEPAD.isPresent() && ItemInit.LASER_POINTER.isPresent()) {
|
||||||
if (item == ItemInit.itemMinePad.get())
|
if (item == ItemInit.MINEPAD.get())
|
||||||
renderer = minePadRenderer;
|
renderer = minePadRenderer;
|
||||||
else if (item == ItemInit.itemLaserPointer.get())
|
else if (item == ItemInit.LASER_POINTER.get())
|
||||||
renderer = laserPointerRenderer;
|
renderer = laserPointerRenderer;
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
@ -801,8 +801,8 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
ItemStack item = inv.get(i);
|
ItemStack item = inv.get(i);
|
||||||
|
|
||||||
if (ItemInit.itemMinePad.isPresent()) {
|
if (ItemInit.MINEPAD.isPresent()) {
|
||||||
if (item.getItem() == ItemInit.itemMinePad.get()) {
|
if (item.getItem() == ItemInit.MINEPAD.get()) {
|
||||||
CompoundTag tag = item.getTag();
|
CompoundTag tag = item.getTag();
|
||||||
|
|
||||||
if (tag != null && tag.contains("PadID"))
|
if (tag != null && tag.contains("PadID"))
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public final class LaserPointerRenderer implements IItemRenderer {
|
||||||
ClientProxy.mouseOn ||
|
ClientProxy.mouseOn ||
|
||||||
ItemLaserPointer.isOn()
|
ItemLaserPointer.isOn()
|
||||||
) &&
|
) &&
|
||||||
mc.player.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.itemLaserPointer.get()) &&
|
mc.player.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.LASER_POINTER.get()) &&
|
||||||
(mc.hitResult == null || mc.hitResult.getType() == HitResult.Type.BLOCK || mc.hitResult.getType() == HitResult.Type.MISS);
|
(mc.hitResult == null || mc.hitResult.getType() == HitResult.Type.BLOCK || mc.hitResult.getType() == HitResult.Type.MISS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,9 @@
|
||||||
package net.montoyo.wd.core;
|
package net.montoyo.wd.core;
|
||||||
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.montoyo.wd.WebDisplays;
|
|
||||||
import net.montoyo.wd.init.ItemInit;
|
import net.montoyo.wd.init.ItemInit;
|
||||||
|
|
||||||
public enum CraftComponent {
|
public enum CraftComponent {
|
||||||
|
|
||||||
STONEKEY("stonekey", "StoneKey"),
|
STONEKEY("stonekey", "StoneKey"),
|
||||||
UPGRADE("upgrade", "Upgrade"),
|
UPGRADE("upgrade", "Upgrade"),
|
||||||
PERIPHERAL("peripheral", "Peripheral"),
|
PERIPHERAL("peripheral", "Peripheral"),
|
||||||
|
|
@ -34,7 +32,6 @@ public enum CraftComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack makeItemStack() {
|
public ItemStack makeItemStack() {
|
||||||
return new ItemStack(ItemInit.itemCraftComp.get(), 1);
|
return new ItemStack(ItemInit.getComputerCraftItem(ordinal()).get(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,16 @@
|
||||||
package net.montoyo.wd.core;
|
package net.montoyo.wd.core;
|
||||||
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.montoyo.wd.init.ItemInit;
|
import net.montoyo.wd.item.ItemUpgrade;
|
||||||
|
|
||||||
public enum DefaultUpgrade {
|
public enum DefaultUpgrade {
|
||||||
|
|
||||||
LASERMOUSE("lasermouse", "LaserMouse"),
|
LASERMOUSE("lasermouse", "LaserMouse"),
|
||||||
REDINPUT("redinput", "RedInput"),
|
REDINPUT("redinput", "RedInput"),
|
||||||
REDOUTPUT("redoutput", "RedOutput"),
|
REDOUTPUT("redoutput", "RedOutput"),
|
||||||
GPS("gps", "GPS");
|
GPS("gps", "GPS");
|
||||||
|
|
||||||
private final String name;
|
public final String name;
|
||||||
private final String wikiName;
|
public final String wikiName;
|
||||||
|
|
||||||
DefaultUpgrade(String n, String wn) {
|
DefaultUpgrade(String n, String wn) {
|
||||||
name = n;
|
name = n;
|
||||||
|
|
@ -27,19 +26,25 @@ public enum DefaultUpgrade {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static boolean matches(ItemStack stack, DefaultUpgrade upgrade) {
|
||||||
|
if (stack.getItem() instanceof ItemUpgrade upgrade1)
|
||||||
|
return upgrade1.type == upgrade;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean matchesLaserMouse(ItemStack is) {
|
public boolean matchesLaserMouse(ItemStack is) {
|
||||||
return is.getItem() == ItemInit.laserMouse.get();
|
return matches(is, LASERMOUSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matchesRedInput(ItemStack is) {
|
public boolean matchesRedInput(ItemStack is) {
|
||||||
return is.getItem() == ItemInit.redInput.get();
|
return matches(is, REDINPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matchesRedOutput(ItemStack is) {
|
public boolean matchesRedOutput(ItemStack is) {
|
||||||
return is.getItem() == ItemInit.redOutput.get();
|
return matches(is, REDOUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matchesGps(ItemStack is) {
|
public boolean matchesGps(ItemStack is) {
|
||||||
return is.getItem() == ItemInit.gps.get();
|
return matches(is, GPS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -503,7 +503,7 @@ public class TileEntityScreen extends BlockEntity {
|
||||||
|
|
||||||
private static Player getLaserUser(Screen scr) {
|
private static Player getLaserUser(Screen scr) {
|
||||||
if (scr.laserUser != null) {
|
if (scr.laserUser != null) {
|
||||||
if (scr.laserUser.isRemoved() || !scr.laserUser.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.itemLaserPointer.get()))
|
if (scr.laserUser.isRemoved() || !scr.laserUser.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.LASER_POINTER.get()))
|
||||||
scr.laserUser = null;
|
scr.laserUser = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,54 +7,63 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import net.minecraftforge.registries.RegistryObject;
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
import net.montoyo.wd.WebDisplays;
|
import net.montoyo.wd.WebDisplays;
|
||||||
import net.montoyo.wd.block.WDBlockContainer;
|
|
||||||
import net.montoyo.wd.block.item.KeyboardItem;
|
import net.montoyo.wd.block.item.KeyboardItem;
|
||||||
import net.montoyo.wd.core.CraftComponent;
|
import net.montoyo.wd.core.CraftComponent;
|
||||||
import net.montoyo.wd.core.DefaultUpgrade;
|
import net.montoyo.wd.core.DefaultUpgrade;
|
||||||
import net.montoyo.wd.item.*;
|
import net.montoyo.wd.item.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "unused"})
|
||||||
public class ItemInit{
|
public class ItemInit{
|
||||||
|
|
||||||
public static void init(IEventBus bus) {
|
public static void init(IEventBus bus) {
|
||||||
ITEMS.register(bus);
|
ITEMS.register(bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "webdisplays");
|
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "webdisplays");
|
||||||
public static RegistryObject<Item> itemCraftComp = null;
|
|
||||||
|
|
||||||
public static RegistryObject<Item> laserMouse = null;
|
protected static final RegistryObject<Item>[] COMP_CRAFT_ITEMS = new RegistryObject[CraftComponent.values().length];
|
||||||
public static RegistryObject<Item> redInput = null;
|
protected static final RegistryObject<Item>[] UPGRADE_ITEMS = new RegistryObject[DefaultUpgrade.values().length];
|
||||||
public static RegistryObject<Item> redOutput = null;
|
|
||||||
public static RegistryObject<Item> gps = null;
|
|
||||||
|
|
||||||
public static final RegistryObject<Item> itemScreenCfg = ITEMS.register("screencfg", () -> new ItemScreenConfigurator(new Item.Properties()));
|
public static final RegistryObject<Item> CONFIGURATOR = ITEMS.register("screencfg", () -> new ItemScreenConfigurator(new Item.Properties()));
|
||||||
public static final RegistryObject<Item> itemOwnerThief = ITEMS.register("ownerthief", () -> new ItemOwnershipThief(new Item.Properties()));
|
public static final RegistryObject<Item> OWNERSHIP_THEIF = ITEMS.register("ownerthief", () -> new ItemOwnershipThief(new Item.Properties()));
|
||||||
public static final RegistryObject<Item> itemLinker = ITEMS.register("linker", () -> new ItemLinker(new Item.Properties()));
|
public static final RegistryObject<Item> LINKER = ITEMS.register("linker", () -> new ItemLinker(new Item.Properties()));
|
||||||
public static final RegistryObject<Item> itemMinePad = ITEMS.register("minepad", () -> new ItemMinePad2(new Item.Properties()));
|
public static final RegistryObject<Item> MINEPAD = ITEMS.register("minepad", () -> new ItemMinePad2(new Item.Properties()));
|
||||||
public static final RegistryObject<Item> itemLaserPointer = ITEMS.register("laserpointer", () -> new ItemLaserPointer(new Item.Properties()));
|
public static final RegistryObject<Item> LASER_POINTER = ITEMS.register("laserpointer", () -> new ItemLaserPointer(new Item.Properties()));
|
||||||
|
|
||||||
public static void registerUpgrade() {
|
static {
|
||||||
laserMouse = ITEMS.register("upgrade_" + DefaultUpgrade.LASERMOUSE.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
|
DefaultUpgrade[] defaultUpgrades = DefaultUpgrade.values();
|
||||||
redInput = ITEMS.register("upgrade_" + DefaultUpgrade.REDINPUT.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
|
for (int i = 0; i < defaultUpgrades.length; i++) {
|
||||||
redOutput = ITEMS.register("upgrade_" + DefaultUpgrade.REDOUTPUT.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
|
DefaultUpgrade upgrade = defaultUpgrades[i];
|
||||||
gps = ITEMS.register("upgrade_" + DefaultUpgrade.GPS.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
|
UPGRADE_ITEMS[i] = ITEMS.register("upgrade_" + upgrade.name().toLowerCase(Locale.ROOT), () -> new ItemUpgrade(upgrade));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerComponents() {
|
CraftComponent[] components = CraftComponent.values();
|
||||||
for (CraftComponent cc : CraftComponent.values()) {
|
for (int i = 0; i < components.length; i++) {
|
||||||
itemCraftComp = ITEMS.register("craftcomp_" + cc.name().toLowerCase(Locale.ROOT), () -> new ItemCraftComponent(new Item.Properties()));
|
CraftComponent cc = components[i];
|
||||||
|
COMP_CRAFT_ITEMS[i] = ITEMS.register("craftcomp_" + cc.name().toLowerCase(Locale.ROOT), () -> new ItemCraftComponent(new Item.Properties()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final RegistryObject<Item> screen = ITEMS.register("screen", () -> new BlockItem(BlockInit.blockScreen.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
public static final RegistryObject<Item> SCREEN = ITEMS.register("screen", () -> new BlockItem(BlockInit.blockScreen.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
||||||
|
|
||||||
public static final RegistryObject<Item> keyboard = ITEMS.register("keyboard", () -> new KeyboardItem(BlockInit.blockKeyBoard.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
|
||||||
public static final RegistryObject<Item> redctrl = ITEMS.register("redctrl", () -> new BlockItem(BlockInit.blockRedControl.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
|
||||||
public static final RegistryObject<Item> rctrl = ITEMS.register("rctrl", () -> new BlockItem(BlockInit.blockRControl.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
|
||||||
public static final RegistryObject<Item> server = ITEMS.register("server", () -> new BlockItem(BlockInit.blockServer.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
|
||||||
|
|
||||||
|
public static final RegistryObject<Item> KEYBOARD = ITEMS.register("keyboard", () -> new KeyboardItem(BlockInit.blockKeyBoard.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
||||||
|
public static final RegistryObject<Item> REDSTONE_CONTROLLER = ITEMS.register("redctrl", () -> new BlockItem(BlockInit.blockRedControl.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
||||||
|
public static final RegistryObject<Item> REMOTE_CONTROLLER = ITEMS.register("rctrl", () -> new BlockItem(BlockInit.blockRControl.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
||||||
|
public static final RegistryObject<Item> SERVER = ITEMS.register("server", () -> new BlockItem(BlockInit.blockServer.get(), new Item.Properties().tab(WebDisplays.CREATIVE_TAB)));
|
||||||
|
|
||||||
|
public static RegistryObject<Item> getComputerCraftItem(int index) {
|
||||||
|
return COMP_CRAFT_ITEMS[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RegistryObject<Item> getUpgradeItem(int index) {
|
||||||
|
return UPGRADE_ITEMS[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCompCraftItem(Item item) {
|
||||||
|
for (RegistryObject<Item> itemRegistryObject : COMP_CRAFT_ITEMS)
|
||||||
|
if (item == itemRegistryObject.get())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
package net.montoyo.wd.item;
|
package net.montoyo.wd.item;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.montoyo.wd.WebDisplays;
|
import net.montoyo.wd.WebDisplays;
|
||||||
import net.montoyo.wd.core.DefaultUpgrade;
|
import net.montoyo.wd.core.DefaultUpgrade;
|
||||||
|
|
@ -17,9 +18,11 @@ import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ItemUpgrade extends ItemMulti implements IUpgrade, WDItem {
|
public class ItemUpgrade extends ItemMulti implements IUpgrade, WDItem {
|
||||||
|
public final DefaultUpgrade type;
|
||||||
public ItemUpgrade() {
|
|
||||||
|
public ItemUpgrade(DefaultUpgrade type) {
|
||||||
super(DefaultUpgrade.class, new Properties().tab(WebDisplays.CREATIVE_TAB));
|
super(DefaultUpgrade.class, new Properties().tab(WebDisplays.CREATIVE_TAB));
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -36,18 +39,20 @@ public class ItemUpgrade extends ItemMulti implements IUpgrade, WDItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSameUpgrade(@Nonnull ItemStack myStack, @Nonnull ItemStack otherStack) {
|
public boolean isSameUpgrade(@Nonnull ItemStack myStack, @Nonnull ItemStack otherStack) {
|
||||||
return otherStack.getItem() == this;
|
if (myStack.getItem() instanceof ItemUpgrade upgrade0) {
|
||||||
|
if (otherStack.getItem() instanceof ItemUpgrade upgrade1) {
|
||||||
|
return upgrade0.type == upgrade1.type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getJSName(@Nonnull ItemStack is) {
|
public String getJSName(@Nonnull ItemStack is) {
|
||||||
ItemStack meta = is;
|
Item item = is.getItem();
|
||||||
DefaultUpgrade[] upgrades = DefaultUpgrade.values();
|
if (item instanceof ItemUpgrade upgrade)
|
||||||
|
return "webdisplays:" + upgrade.type.toString();
|
||||||
if(meta.isEmpty())
|
return "webdisplays:null";
|
||||||
return "webdisplays:wtf";
|
|
||||||
else
|
|
||||||
return "webdisplays:" + is;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class MouseHandlerMixin {
|
||||||
if (Minecraft.getInstance().screen == null) {
|
if (Minecraft.getInstance().screen == null) {
|
||||||
if (
|
if (
|
||||||
minecraft.player != null && minecraft.level != null &&
|
minecraft.player != null && minecraft.level != null &&
|
||||||
minecraft.player.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.itemLaserPointer.get()) &&
|
minecraft.player.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.LASER_POINTER.get()) &&
|
||||||
(minecraft.hitResult == null || minecraft.hitResult.getType() == HitResult.Type.BLOCK || minecraft.hitResult.getType() == HitResult.Type.MISS)
|
(minecraft.hitResult == null || minecraft.hitResult.getType() == HitResult.Type.BLOCK || minecraft.hitResult.getType() == HitResult.Type.MISS)
|
||||||
) {
|
) {
|
||||||
ItemLaserPointer.press(flag, p_91532_);
|
ItemLaserPointer.press(flag, p_91532_);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user