* Start on 1.19.3 port * Client runs, kinda * Fix crash when opening item group * Fix dynamic models * Add atlas config for slot sprites * Ore :) * Rubber tree's, lakes and ore cleanup * Add blocks to item group * Fix rubber tree sapling * added vanilla creative and missing peridot pickaxe (#3076) * added vanilla creative and missing peridot pickaxe * some small tweaks Co-authored-by: ayutac <fly.high.android@gmail.com> * added bamboo saw mill datagen recipes (#3077) * added bamboo saw mill datagen recipes * fixed datagen error Co-authored-by: ayutac <fly.high.android@gmail.com> * 1.19.3-rc1 * 1.19.3 port villager housing (#3082) * added NBTs for the houses * added the houses, theoretically * added the houses, practically * made house gen configurable Co-authored-by: ayutac <fly.high.android@gmail.com> * Fixes #3083 * reordered TR creative tab and small tweaks to the rest (#3081) * reordered TR creative tab and small tweaks to the rest * small bugfix Co-authored-by: ayutac <fly.high.android@gmail.com> * 1.19.3 * Bump version Co-authored-by: Ayutac <skoch02@students.uni-mainz.de> Co-authored-by: ayutac <fly.high.android@gmail.com>
111 lines
3.5 KiB
Java
111 lines
3.5 KiB
Java
/*
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
*
|
|
* Copyright (c) 2020 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.items;
|
|
|
|
import net.minecraft.client.item.TooltipContext;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.text.Text;
|
|
import net.minecraft.util.ActionResult;
|
|
import net.minecraft.util.Hand;
|
|
import net.minecraft.util.TypedActionResult;
|
|
import net.minecraft.world.World;
|
|
import org.jetbrains.annotations.Nullable;
|
|
import reborncore.common.powerSystem.RcEnergyItem;
|
|
import reborncore.common.powerSystem.RcEnergyTier;
|
|
import reborncore.common.util.ItemUtils;
|
|
|
|
import java.util.List;
|
|
|
|
public class BatteryItem extends Item implements RcEnergyItem {
|
|
|
|
private final int maxEnergy;
|
|
private final RcEnergyTier tier;
|
|
|
|
public BatteryItem(int maxEnergy, RcEnergyTier tier) {
|
|
super(new Item.Settings().maxCount(1));
|
|
this.maxEnergy = maxEnergy;
|
|
this.tier = tier;
|
|
}
|
|
|
|
// Item
|
|
@Override
|
|
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {
|
|
final ItemStack stack = player.getStackInHand(hand);
|
|
if (player.isSneaking()) {
|
|
ItemUtils.switchActive(stack, 1, player);
|
|
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
|
}
|
|
return new TypedActionResult<>(ActionResult.PASS, stack);
|
|
}
|
|
|
|
@Override
|
|
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
|
ItemUtils.checkActive(stack, 1, entity);
|
|
if (world.isClient) {
|
|
return;
|
|
}
|
|
if (!ItemUtils.isActive(stack)){
|
|
return;
|
|
}
|
|
if (entity instanceof PlayerEntity) {
|
|
ItemUtils.distributePowerToInventory((PlayerEntity) entity, stack, tier.getMaxOutput(), (testStack) -> !(testStack.getItem() instanceof BatteryItem));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void appendTooltip(ItemStack stack, @Nullable World worldIn, List<Text> tooltip, TooltipContext flagIn) {
|
|
ItemUtils.buildActiveTooltip(stack, tooltip);
|
|
}
|
|
|
|
// EnergyHolder
|
|
@Override
|
|
public long getEnergyCapacity() {
|
|
return maxEnergy;
|
|
}
|
|
|
|
@Override
|
|
public RcEnergyTier getTier() {
|
|
return tier;
|
|
}
|
|
|
|
// ItemDurabilityExtensions
|
|
@Override
|
|
public int getItemBarStep(ItemStack stack) {
|
|
return ItemUtils.getPowerForDurabilityBar(stack);
|
|
}
|
|
|
|
@Override
|
|
public boolean isItemBarVisible(ItemStack stack) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getItemBarColor(ItemStack stack) {
|
|
return ItemUtils.getColorForDurabilityBar(stack);
|
|
}
|
|
}
|