Merge remote-tracking branch 'origin/1.16' into 1.16

This commit is contained in:
modmuss50 2020-10-30 21:03:04 +00:00
commit 1d00090cb4
8 changed files with 112 additions and 78 deletions

View file

@ -50,9 +50,7 @@ public class AlarmBlockEntity extends BlockEntity
}
public void rightClick() {
if (world.isClient) {
return;
}
if (world == null || world.isClient) return;
if (selectedSound < 3) {
selectedSound++;
@ -84,15 +82,12 @@ public class AlarmBlockEntity extends BlockEntity
super.fromTag(blockState, compound);
}
// ITickable
// Tickable
@Override
public void tick() {
if (world.isClient()) {
return;
}
if (world.getTime() % 25 != 0) {
return;
}
if (world == null || world.isClient()) return;
if (world.getTime() % 25 != 0) return;
if (world.isReceivingRedstonePower(getPos())) {
BlockAlarm.setActive(true, world, pos);
switch (selectedSound) {

View file

@ -33,7 +33,6 @@ import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
@ -48,25 +47,16 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
super(TRBlockEntities.CHARGE_O_MAT);
}
// TilePowerAcceptor
// PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
if (world.isClient) {
if (world == null || world.isClient) {
return;
}
for (int i = 0; i < 6; i++) {
ItemStack stack = inventory.getStack(i);
if (Energy.valid(stack)) {
Energy.of(this)
.into(
Energy
.of(stack)
)
.move();
}
discharge(i);
}
}
@ -77,7 +67,8 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
@Override
public boolean canProvideEnergy(EnergySide side) {
return false;
// This allows to move energy from BE to chargeable item. #2264
return side == EnergySide.UNKNOWN;
}
@Override
@ -90,7 +81,7 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
return TechRebornConfig.chargeOMatBMaxInput;
}
// TileMachineBase
// MachineBaseBlockEntity
@Override
public boolean canBeUpgraded() {
return false;
@ -102,13 +93,13 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
return TRContent.Machine.CHARGE_O_MAT.getStack();
}
// ItemHandlerProvider
// InventoryProvider
@Override
public RebornInventory<ChargeOMatBlockEntity> getInventory() {
return inventory;
}
// IContainerProvider
// BuiltScreenHandlerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("chargebench").player(player.inventory).inventory().hotbar().addInventory()

View file

@ -25,6 +25,7 @@
package techreborn.blockentity.storage.item;
import net.minecraft.block.BlockState;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
@ -435,8 +436,12 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
.append(
new LiteralText(String.valueOf(this.getMaxCapacity()))
.formatted(Formatting.GOLD)
.append(" items (")
.append(" ")
.append(I18n.translate("techreborn.tooltip.unit.items"))
.append(" (")
.append(String.valueOf(this.getMaxCapacity() / 64))
.append(" ")
.append(I18n.translate("techreborn.tooltip.unit.stacks"))
.append(")")
)
);

View file

@ -26,6 +26,7 @@ package techreborn.blocks.misc;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.minecraft.block.*;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
@ -44,6 +45,7 @@ import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.util.WorldUtils;
import team.reborn.energy.Energy;
import techreborn.events.TRRecipeHandler;
@ -61,20 +63,29 @@ public class BlockRubberLog extends PillarBlock {
public static DirectionProperty SAP_SIDE = Properties.HORIZONTAL_FACING;
public static BooleanProperty HAS_SAP = BooleanProperty.of("hassap");
public static BooleanProperty SHOULD_SAP = BooleanProperty.of("shouldsap");
public BlockRubberLog() {
super(Settings.of(Material.WOOD, (blockState) -> MaterialColor.SPRUCE)
.strength(2.0F, 2f)
.sounds(BlockSoundGroup.WOOD)
.ticksRandomly());
this.setDefaultState(this.getDefaultState().with(SAP_SIDE, Direction.NORTH).with(HAS_SAP, false).with(AXIS, Direction.Axis.Y));
this.setDefaultState(this.getDefaultState().with(SAP_SIDE, Direction.NORTH).with(HAS_SAP, false).with(SHOULD_SAP, true).with(AXIS, Direction.Axis.Y));
FlammableBlockRegistry.getDefaultInstance().add(this, 5, 5);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(SAP_SIDE, HAS_SAP);
builder.add(SAP_SIDE, HAS_SAP, SHOULD_SAP);
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
super.onPlaced(world, pos, state, placer, itemStack);
if (placer instanceof PlayerEntity) {
world.setBlockState(pos, state.with(SHOULD_SAP, false));
}
}
@Override
@ -82,6 +93,7 @@ public class BlockRubberLog extends PillarBlock {
return tagIn == BlockTags.LOGS;
}
@SuppressWarnings("deprecation")
@Override
public void onBreak(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
int i = 4;
@ -98,15 +110,14 @@ public class BlockRubberLog extends PillarBlock {
super.onBreak(worldIn, pos, state, player);
}
@SuppressWarnings("deprecation")
@Override
public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
super.randomTick(state, worldIn, pos, random);
if (state.get(AXIS) != Direction.Axis.Y) {
return;
}
if (state.get(HAS_SAP)) {
return;
}
if (state.get(AXIS) != Direction.Axis.Y) return;
if (!state.get(SHOULD_SAP)) return;
if (state.get(HAS_SAP)) return;
if (random.nextInt(50) == 0) {
Direction facing = Direction.fromHorizontal(random.nextInt(4));
if (worldIn.getBlockState(pos.offset(Direction.DOWN, 1)).getBlock() == this
@ -116,6 +127,7 @@ public class BlockRubberLog extends PillarBlock {
}
}
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn,
Hand hand, BlockHitResult hitResult) {

View file

@ -25,19 +25,20 @@
package techreborn.events;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.event.client.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.registry.Registry;
import reborncore.api.IListInfoProvider;
@ -51,27 +52,20 @@ import techreborn.TechReborn;
import techreborn.init.TRContent;
import techreborn.items.UpgradeItem;
import techreborn.utils.ToolTipAssistUtils;
import techreborn.utils.WIP;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class StackToolTipHandler implements ItemTooltipCallback {
private static final ArrayList<Block> wipBlocks = new ArrayList<>();
public static final Map<Item, Boolean> ITEM_ID = Maps.newHashMap();
public static void setup() {
ItemTooltipCallback.EVENT.register(new StackToolTipHandler());
// WIP injection
// wipBlocks.add(TRContent.Machine.NAME.block);
}
@Override
public void getTooltip(ItemStack stack, TooltipContext tooltipContext, List<Text> components) {
public void getTooltip(ItemStack stack, TooltipContext tooltipContext, List<Text> tooltipLines) {
Item item = stack.getItem();
if (!ITEM_ID.computeIfAbsent(item, this::isTRItem))
@ -80,55 +74,78 @@ public class StackToolTipHandler implements ItemTooltipCallback {
// Machine info and upgrades helper section
Block block = Block.getBlockFromItem(item);
if (wipBlocks.contains(block) || block instanceof WIP) {
components.add(new TranslatableText("techreborn.tooltip.wip").formatted(Formatting.RED));
}
if (block instanceof BaseBlockEntityProvider) {
ToolTipAssistUtils.addInfo(item.getTranslationKey(), components);
ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines);
}
if (item instanceof UpgradeItem) {
UpgradeItem upgrade = (UpgradeItem) item;
ToolTipAssistUtils.addInfo(item.getTranslationKey(), components, false);
components.addAll(ToolTipAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown()));
ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines, false);
tooltipLines.addAll(ToolTipAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown()));
}
// Other section
if (item instanceof IListInfoProvider) {
((IListInfoProvider) item).addInfo(components, false, false);
} else if (stack.getItem() instanceof EnergyHolder) {
((IListInfoProvider) item).addInfo(tooltipLines, false, false);
} else if (item instanceof EnergyHolder) {
LiteralText line1 = new LiteralText(PowerSystem.getLocalizedPowerNoSuffix(Energy.of(stack).getEnergy()));
line1.append("/");
line1.append(PowerSystem.getLocalizedPowerNoSuffix(Energy.of(stack).getMaxStored()));
line1.append(" ");
line1.append(PowerSystem.getDisplayPower().abbreviation);
line1.append(PowerSystem.getLocalizedPower(Energy.of(stack).getMaxStored()));
line1.formatted(Formatting.GOLD);
components.add(1, line1);
tooltipLines.add(1, line1);
if (Screen.hasShiftDown()) {
int percentage = percentage(Energy.of(stack).getMaxStored(), Energy.of(stack).getEnergy());
Formatting color = StringUtils.getPercentageColour(percentage);
components.add(2, new LiteralText(color + "" + percentage + "%" + Formatting.GRAY + " Charged"));
// TODO: show both input and output rates
components.add(3, new LiteralText(Formatting.GRAY + "I/O Rate: " + Formatting.GOLD + PowerSystem.getLocalizedPower(((EnergyHolder) item).getMaxInput(EnergySide.UNKNOWN))));
MutableText line2 = StringUtils.getPercentageText(percentage);
line2.append(" ");
line2.formatted(Formatting.GRAY);
line2.append(I18n.translate("reborncore.gui.tooltip.power_charged"));
tooltipLines.add(2, line2);
double inputRate = ((EnergyHolder) item).getMaxInput(EnergySide.UNKNOWN);
double outputRate = ((EnergyHolder) item).getMaxOutput(EnergySide.UNKNOWN);
LiteralText line3 = new LiteralText("");
if (inputRate != 0 && inputRate == outputRate){
line3.append(I18n.translate("techreborn.tooltip.transferRate"));
line3.append(" : ");
line3.formatted(Formatting.GRAY);
line3.append(PowerSystem.getLocalizedPower(inputRate));
line3.formatted(Formatting.GOLD);
}
else if(inputRate != 0){
line3.append(I18n.translate("reborncore.tooltip.energy.inputRate"));
line3.append(" : ");
line3.formatted(Formatting.GRAY);
line3.append(PowerSystem.getLocalizedPower(inputRate));
line3.formatted(Formatting.GOLD);
}
else if (outputRate !=0){
line3.append(I18n.translate("reborncore.tooltip.energy.outputRate"));
line3.append(" : ");
line3.formatted(Formatting.GRAY);
line3.append(PowerSystem.getLocalizedPower(outputRate));
line3.formatted(Formatting.GOLD);
}
tooltipLines.add(3, line3);
}
} else {
try {
if ((block instanceof BlockEntityProvider) && Registry.BLOCK.getId(block).getNamespace().contains("techreborn")) {
if ((block instanceof BlockEntityProvider) && isTRBlock(block)) {
BlockEntity blockEntity = ((BlockEntityProvider) block).createBlockEntity(MinecraftClient.getInstance().world);
boolean hasData = false;
if (stack.hasTag() && stack.getTag().contains("blockEntity_data")) {
CompoundTag blockEntityData = stack.getTag().getCompound("blockEntity_data");
blockEntity.fromTag(blockEntity.getCachedState(), blockEntityData);
hasData = true;
components.add(new LiteralText("Block data contained").formatted(Formatting.DARK_GREEN));
if (stack.hasTag() && stack.getOrCreateTag().contains("blockEntity_data")) {
CompoundTag blockEntityData = stack.getOrCreateTag().getCompound("blockEntity_data");
if (blockEntity != null) {
blockEntity.fromTag(block.getDefaultState(), blockEntityData);
hasData = true;
tooltipLines.add(new LiteralText(I18n.translate("techreborn.tooltip.has_data")).formatted(Formatting.DARK_GREEN));
}
}
if (blockEntity instanceof IListInfoProvider) {
((IListInfoProvider) blockEntity).addInfo(components, false, hasData);
((IListInfoProvider) blockEntity).addInfo(tooltipLines, false, hasData);
}
}
} catch (NullPointerException e) {
@ -141,6 +158,10 @@ public class StackToolTipHandler implements ItemTooltipCallback {
return Registry.ITEM.getId(item).getNamespace().equals("techreborn");
}
private boolean isTRBlock(Block block){
return Registry.BLOCK.getId(block).getNamespace().contains("techreborn");
}
public int percentage(int MaxValue, int CurrentValue) {
if (CurrentValue == 0)
return 0;

View file

@ -30,6 +30,7 @@ import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.BlockState;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
@ -137,7 +138,7 @@ public class OmniToolItem extends PickaxeItem implements EnergyHolder, ItemDurab
@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack stack, @Nullable World worldIn, List<Text> tooltip, TooltipContext flagIn) {
tooltip.add(new LiteralText(Formatting.YELLOW + "Swiss Army Knife"));
tooltip.add(new LiteralText(Formatting.YELLOW + I18n.translate("techreborn.tooltip.omnitool_motto")));
}
// ItemDurabilityExtensions

View file

@ -53,23 +53,23 @@ public class ToolTipAssistUtils {
switch (upgradeType) {
case OVERCLOCKER:
tips.add(getPositive("Speed increase", calculateValue(TechRebornConfig.overclockerSpeed * 100, count, shiftHeld), "%"));
tips.add(getNegative("Energy increase", calculateValue(TechRebornConfig.overclockerPower * 100, count, shiftHeld), "%"));
tips.add(getPositive(I18n.translate("techreborn.tooltip.upgrade.speed_increase"), calculateValue(TechRebornConfig.overclockerSpeed * 100, count, shiftHeld), "%"));
tips.add(getNegative(I18n.translate("techreborn.tooltip.upgrade.energy_increase"), calculateValue(TechRebornConfig.overclockerPower * 100, count, shiftHeld), "%"));
break;
case TRANSFORMER:
shouldStackCalculate = false;
break;
case ENERGY_STORAGE:
tips.add(getPositive("Storage increase", calculateValue(TechRebornConfig.energyStoragePower, count, shiftHeld), " E"));
tips.add(getPositive(I18n.translate("techreborn.tooltip.upgrade.storage_increase"), calculateValue(TechRebornConfig.energyStoragePower, count, shiftHeld), " E"));
break;
case SUPERCONDUCTOR:
tips.add(getPositive("Increased flow by: ", calculateValue(Math.pow(2, (TechRebornConfig.superConductorCount + 2)) * 100, count, shiftHeld), "%"));
tips.add(getPositive(I18n.translate("techreborn.tooltip.upgrade.flow_increase"), calculateValue(Math.pow(2, (TechRebornConfig.superConductorCount + 2)) * 100, count, shiftHeld), "%"));
break;
}
// Add reminder that they can use shift to calculate the entire stack
if (shouldStackCalculate && !shiftHeld) {
tips.add(new LiteralText(instructColour + "Hold shift for stack calculation"));
tips.add(new LiteralText(instructColour + I18n.translate("techreborn.tooltip.more_info")));
}
return tips;
@ -91,7 +91,7 @@ public class ToolTipAssistUtils {
list.add(new LiteralText(infoColour + infoLine));
}
} else {
list.add(new LiteralText(instructColour + "Hold shift for info"));
list.add(new LiteralText(instructColour + I18n.translate("techreborn.tooltip.more_info")));
}
}
}

View file

@ -711,7 +711,7 @@
"techreborn.message.nightgen": "Panel in reduced sunlight",
"techreborn.message.zerogen": "Panel obstructed from sky",
"techreborn.message.info.item.techreborn.overclocker_upgrade": "Increases speed at the cost of more energy",
"techreborn.message.info.item.techreborn.overclocker_upgrade": "Increases speed at the cost of more energy used per tick",
"techreborn.message.info.item.techreborn.transformer_upgrade": "Increase energy tier",
"techreborn.message.info.item.techreborn.energy_storage_upgrade": "Increase energy store",
"techreborn.message.info.item.techreborn.superconductor_upgrade": "Increases energy flow rate",
@ -813,6 +813,10 @@
"techreborn.tooltip.wip": "WIP Coming Soon",
"techreborn.tooltip.inventory": "Inventory",
"techreborn.tooltip.upgrades": "Upgrades",
"techreborn.tooltip.upgrade.speed_increase": "Speed increase",
"techreborn.tooltip.upgrade.energy_increase": "Energy increase",
"techreborn.tooltip.upgrade.storage_increase": "Storage increase",
"techreborn.tooltip.upgrade.flow_increase": "Increased flow by",
"techreborn.tooltip.alarm": "Shift right-click to change sound",
"techreborn.tooltip.invalid_basin_placement": "Resin basin must be placed on a valid rubber tree.",
"techreborn.tooltip.generationRate.day": "Generation Rate Day",
@ -821,9 +825,14 @@
"techreborn.tooltip.unit.capacity": "Capacity: ",
"techreborn.tooltip.unit.empty": "Empty",
"techreborn.tooltip.unit.divider": " of ",
"techreborn.tooltip.unit.items": "items",
"techreborn.tooltip.unit.stacks": "stacks",
"techreborn.tooltip.painting_tool.select": "Shift right click on block to set style",
"techreborn.tooltip.painting_tool.apply": "Right click on covered cable to apply",
"techreborn.tooltip.cable.can_cover": "Can be covered with wooden plates",
"techreborn.tooltip.more_info": "Hold Shift for more info",
"techreborn.tooltip.has_data": "Stored data",
"techreborn.tooltip.omnitool_motto" : "Swiss Army Knife",
"_comment23": "ManualUI",
"techreborn.manual.wiki": "Online wiki",