Fix Cloaking Device

This commit is contained in:
drcrazy 2019-12-17 17:36:24 +03:00
parent 1f0fa709bc
commit b298727563
4 changed files with 36 additions and 80 deletions

View file

@ -79,7 +79,6 @@ public class TechReborn implements ModInitializer {
//Force loads the block entities at the right time
TRBlockEntities.THERMAL_GEN.toString();
// Scrapbox
if (TechRebornConfig.dispenseScrapboxes) {
DispenserBlock.registerBehavior(TRContent.SCRAP_BOX, new BehaviorDispenseScrapbox());

View file

@ -1,50 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.events;
import net.minecraft.item.Item;
public class TRTickHandler {
public Item previouslyWearing;
//TODO fixable with a newer version of fabric
//
// @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
// public void onPlayerTick(TickEvent.PlayerTickEvent e) {
// PlayerEntity player = e.player;
// Item chestslot = !player.getEquippedStack(EquipmentSlot.CHEST).isEmpty()
// ? player.getEquippedStack(EquipmentSlot.CHEST).getItem() : null;
//
// if (previouslyWearing != chestslot && previouslyWearing == TRContent.CLOAKING_DEVICE && player.isInvisible()
// && !player.hasStatusEffect(StatusEffects.INVISIBILITY)) {
// player.setInvisible(false);
// }
//
// previouslyWearing = chestslot;
// }
}

View file

@ -34,6 +34,8 @@ import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DefaultedList;
import net.minecraft.world.World;
import reborncore.api.items.ArmorRemoveHandler;
import reborncore.api.items.ArmorTickable;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
@ -45,7 +47,7 @@ import techreborn.init.TRArmorMaterial;
import techreborn.init.TRContent;
import techreborn.utils.InitUtils;
public class ItemCloakingDevice extends ItemTRArmour implements EnergyHolder {
public class ItemCloakingDevice extends ItemTRArmour implements EnergyHolder, ArmorTickable, ArmorRemoveHandler {
public static int maxCharge = TechRebornConfig.cloakingDeviceCharge;
public static int usage = TechRebornConfig.cloackingDeviceUsage;
@ -57,32 +59,7 @@ public class ItemCloakingDevice extends ItemTRArmour implements EnergyHolder {
super(TRArmorMaterial.CLOAKING, EquipmentSlot.CHEST);
}
@Override
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (entityIn instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entityIn;
if (Energy.valid(stack)) {
if(Energy.of(stack).use(usage)){
player.setInvisible(true);
} else {
if (!player.hasStatusEffect(StatusEffects.INVISIBILITY)) {
player.setInvisible(false);
}
}
}
}
}
@Environment(EnvType.CLIENT)
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> itemList) {
if (!isIn(group)) {
return;
}
InitUtils.initPoweredItems(TRContent.CLOAKING_DEVICE, itemList);
}
// ItemTRArmour
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
@ -98,7 +75,17 @@ public class ItemCloakingDevice extends ItemTRArmour implements EnergyHolder {
return PowerSystem.getDisplayPower().colour;
}
// IEnergyItemInfo
// Item
@Environment(EnvType.CLIENT)
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> itemList) {
if (!isIn(group)) {
return;
}
InitUtils.initPoweredItems(TRContent.CLOAKING_DEVICE, itemList);
}
// EnergyHolder
@Override
public double getMaxStoredPower() {
return maxCharge;
@ -118,4 +105,24 @@ public class ItemCloakingDevice extends ItemTRArmour implements EnergyHolder {
public double getMaxOutput(EnergySide side) {
return 0;
}
// ArmorTickable
@Override
public void tickArmor(ItemStack stack, PlayerEntity playerEntity) {
if (Energy.of(stack).use(usage)) {
playerEntity.setInvisible(true);
} else {
if (playerEntity.isInvisible()) {
playerEntity.setInvisible(false);
}
}
}
// ArmorRemoveHandler
@Override
public void onRemoved(PlayerEntity playerEntity) {
if (playerEntity.isInvisible()) {
playerEntity.setInvisible(false);
}
}
}

View file

@ -48,7 +48,7 @@ public class ItemTRArmour extends ArmorItem implements ItemDurabilityExtensions
UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")
};
String repairOreDict = "";
String repairOreDict;
public ItemTRArmour(ArmorMaterial material, EquipmentSlot slot) {
this(material, slot, "");