Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparator and Redstone interactivity #2262

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
98046e7
add vessel & barrel redstone interaction
Charnuz Nov 19, 2022
fbed386
powderkeg & crucible redstone
Charnuz Nov 19, 2022
80f590e
blast furnace & bloomery redstone
Charnuz Nov 21, 2022
a48198e
tool rack redstone & change barrel
Charnuz Nov 22, 2022
afc23d5
add quern redstone
Charnuz Nov 22, 2022
1ded7aa
quern dispenser behavior
Charnuz Nov 22, 2022
0414dfa
add lighting blocks with dispensers
Charnuz Dec 3, 2022
380e5c1
fix infinite loop
Charnuz Dec 3, 2022
d240900
use lighting interface for event
Charnuz Dec 3, 2022
5c4e6f7
blast furnaces lightable with dispensers
Charnuz Dec 3, 2022
c865aeb
bloomery lightable with dispensers
Charnuz Dec 3, 2022
70726c8
lamps lightable
Charnuz Dec 3, 2022
416fae6
powderkeg lightable
Charnuz Dec 3, 2022
48fdace
fix infinite durability
Charnuz Dec 3, 2022
c5aa6dc
lighting torches
Charnuz Dec 4, 2022
9a29d57
lightable firepits
Charnuz Dec 4, 2022
d1e1832
fix import issue
Charnuz Dec 4, 2022
38a0a87
lightable candles
Charnuz Dec 4, 2022
6555588
lightable log piles & pit kilns
Charnuz Dec 4, 2022
36b3446
cleanup
Charnuz Dec 4, 2022
1666d1a
nest box redstone
Charnuz Dec 5, 2022
353f731
misc cleanup
Charnuz Dec 18, 2022
0771c95
Merge branch '1.18.x' of https://github.com/TerraFirmaCraft/TerraFirm…
Charnuz Dec 18, 2022
388cfc7
revert changes to StartFireEvent and remove Lightable
Charnuz Dec 18, 2022
d98bad0
add config option for dispenser lighting
Charnuz Dec 18, 2022
8287006
i hate you IDEA
Charnuz Dec 18, 2022
7766cb2
revert changes to StartFireEvent and remove Lightable
Charnuz Dec 18, 2022
6337f50
Merge branch 'redstone' of https://github.com/Charnuz/TerraFirmaCraft…
Charnuz Dec 18, 2022
7eef6c9
Update src/main/java/net/dries007/tfc/mixin/accessor/DispenserBlockAc…
Charnuz Dec 18, 2022
74e131e
Update src/main/java/net/dries007/tfc/util/DispenserBehaviors.java
Charnuz Dec 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/net/dries007/tfc/ForgeEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

import com.mojang.datafixers.util.Pair;
import com.mojang.logging.LogUtils;

import net.dries007.tfc.client.ClientHelpers;
import net.dries007.tfc.common.TFCEffects;
import net.dries007.tfc.common.TFCTags;
Expand Down Expand Up @@ -147,6 +148,7 @@
import net.dries007.tfc.world.chunkdata.ChunkDataCapability;
import net.dries007.tfc.world.chunkdata.ChunkGeneratorExtension;
import net.dries007.tfc.world.settings.RockLayerSettings;

import org.slf4j.Logger;

public final class ForgeEventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ public BarrelRecipe getRecipe()
return recipe;
}

@Override
public int getAnalogValue()
{
return recipe != null ? 1 : 0;
}

public long getSealedTick()
{
return sealedTick;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -656,7 +657,7 @@ private void updateCachedRecipe()
}
}

static class BlastFurnaceInventory extends ItemStackHandler implements BlastFurnaceRecipe.Inventory, DelegateFluidHandler
static class BlastFurnaceInventory extends ItemStackHandler implements BlastFurnaceRecipe.Inventory, DelegateFluidHandler, IAnalogInventory
{
private final BlastFurnaceBlockEntity blastFurnace;

Expand Down Expand Up @@ -684,5 +685,12 @@ public IFluidHandler getFluidHandler()
{
return blastFurnace.outputFluidTank;
}

@Override
public int getAnalogOutput()
{
boolean hasItems = !(blastFurnace.catalystStacks.isEmpty() && blastFurnace.inputStacks.isEmpty());
return (hasItems ? 1 : 0) + Mth.floor((blastFurnace.catalystStacks.size() + blastFurnace.inputStacks.size()) / 2f / blastFurnace.lastKnownCapacity * 14);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.util.Mth;
import net.minecraft.world.Containers;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.item.ItemEntity;
Expand Down Expand Up @@ -442,7 +442,7 @@ public List<ItemStack> getCatalystStacks()
return catalystStacks;
}

static class Inventory extends InventoryItemHandler implements BloomeryInventory
static class Inventory extends InventoryItemHandler implements BloomeryInventory, IAnalogInventory
{
private final BloomeryBlockEntity bloomery;

Expand Down Expand Up @@ -484,5 +484,11 @@ public ItemStack getCatalyst()
{
return bloomery.catalystStacks.isEmpty() ? ItemStack.EMPTY : bloomery.catalystStacks.get(0);
}

@Override
public int getAnalogOutput()
{
return bloomery.cachedRecipe != null ? 1 + Mth.floor(14f * bloomery.getRemainingTicks() / bloomery.cachedRecipe.getDuration()) : 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
Expand Down Expand Up @@ -316,7 +317,7 @@ private void updateCaches()
}
}

static class CrucibleInventory implements DelegateItemHandler, SimpleFluidHandler, INBTSerializable<CompoundTag>, IHeatBlock
static class CrucibleInventory implements DelegateItemHandler, SimpleFluidHandler, INBTSerializable<CompoundTag>, IHeatBlock, IAnalogInventory
{
private final CrucibleBlockEntity crucible;

Expand Down Expand Up @@ -431,5 +432,11 @@ public void setTemperatureIfWarmer(float temperature)
crucible.markForSync();
}
}

@Override
public int getAnalogOutput()
{
return Mth.floor(alloy.getAmount() / (float) alloy.getMaxUnits() * 14.0F) + (alloy.getAmount() > 0 ? 1 : 0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Licensed under the EUPL, Version 1.2.
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
*/

package net.dries007.tfc.common.blockentities;

/**
* Helper for containers that interface with comparators
*/
public interface IAnalogInventory
{
/**
* @return the redstone analog value
*/
int getAnalogOutput();
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ public boolean canInteractWith(Player player)
}
}

public int getAnalogValue()
{
if (inventory instanceof IAnalogInventory analog)
{
return analog.getAnalogOutput();
}
return 0;
}

/**
* A factory interface for the inventory field, allows self references in the constructor
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onSeal()
}
}

public static class VesselInventory extends InventoryItemHandler implements INBTSerializable<CompoundTag>
public static class VesselInventory extends InventoryItemHandler implements INBTSerializable<CompoundTag>, IAnalogInventory
{
private final LargeVesselBlockEntity vessel;

Expand Down Expand Up @@ -102,5 +102,11 @@ private boolean canModify()
{
return !vessel.getBlockState().getValue(LargeVesselBlock.SEALED);
}

@Override
public int getAnalogOutput()
{
return Helpers.getAnalogSignalFrom(vessel.inventory);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -109,4 +108,10 @@ public AbstractContainerMenu createMenu(int windowID, Inventory inv, Player play
{
return NestBoxContainer.create(this, inv, windowID);
}

@Override
public int getAnalogValue()
{
return Helpers.getAnalogSignalFrom(this.inventory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void setLit(boolean lit, @Nullable Entity igniter)
markForSync();
}

public static class PowderkegInventory implements DelegateItemHandler, INBTSerializable<CompoundTag>, EmptyInventory
public static class PowderkegInventory implements DelegateItemHandler, INBTSerializable<CompoundTag>, EmptyInventory, IAnalogInventory
{
private final PowderkegBlockEntity powderkeg;
private final InventoryItemHandler inventory;
Expand Down Expand Up @@ -195,6 +195,12 @@ private boolean canModify()
{
return !powderkeg.getBlockState().getValue(PowderkegBlock.SEALED);
}

@Override
public int getAnalogOutput()
{
return Helpers.getAnalogSignalFrom(inventory);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -205,4 +206,11 @@ private void finishGrinding()
}
}
}

@Override
public int getAnalogValue()
{
ItemStack handstone = inventory.getStackInSlot(SLOT_HANDSTONE);
return handstone.isEmpty() ? 0 : 1 + Mth.floor(14f * handstone.getDamageValue() / handstone.getMaxDamage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -90,4 +89,19 @@ private void insertItem(int slot, ItemStack stack)
level.playSound(null, worldPosition, TFCSounds.TOOL_RACK_PLACE.get(), SoundSource.BLOCKS, 1, 1 + ((level.random.nextFloat() - level.random.nextFloat()) / 16));
}

// Sorry for this.
// This returns a unique analog value for every permutation of items within slots
@Override
public int getAnalogValue()
Comment on lines +92 to +95
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just seems unintuitive to me, imo. Yes, in theory, people could use this to detect which element in a tool rack is present, but it makes much more sense to just output a count of the number of items in the tool rack.

{
int value = 0;
for (int slot = 0; slot < inventory.getSlots(); slot++)
{
if (!inventory.getStackInSlot(slot).isEmpty())
{
value |= 1 << slot;
}
}
return value;
}
}
11 changes: 7 additions & 4 deletions src/main/java/net/dries007/tfc/common/blocks/DeadTorchBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
package net.dries007.tfc.common.blocks;

import java.util.Random;

import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.TorchBlock;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.TorchBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

import net.dries007.tfc.common.blockentities.TickCounterBlockEntity;

public class DeadTorchBlock extends TorchBlock
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
package net.dries007.tfc.common.blocks;

import java.util.Random;

import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.WallTorchBlock;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

import net.dries007.tfc.common.blockentities.TickCounterBlockEntity;

public class DeadWallTorchBlock extends WallTorchBlock
{
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/net/dries007/tfc/common/blocks/LargeVesselBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
package net.dries007.tfc.common.blocks;

import java.util.List;

import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand All @@ -32,13 +30,14 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable;

import net.dries007.tfc.client.TFCSounds;
import net.dries007.tfc.common.blockentities.InventoryBlockEntity;
import net.dries007.tfc.common.blockentities.LargeVesselBlockEntity;
import net.dries007.tfc.common.blockentities.TFCBlockEntities;
import net.dries007.tfc.common.blocks.devices.SealableDeviceBlock;
import net.dries007.tfc.util.Helpers;
import org.jetbrains.annotations.Nullable;

public class LargeVesselBlock extends SealableDeviceBlock
{
Expand Down Expand Up @@ -134,4 +133,16 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
}
return InteractionResult.SUCCESS;
}

@Override
public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos)
{
return level.getBlockEntity(pos, TFCBlockEntities.LARGE_VESSEL.get()).map(InventoryBlockEntity::getAnalogValue).orElse(super.getAnalogOutputSignal(state, level, pos));
}

@Override
public boolean hasAnalogOutputSignal(BlockState state)
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
package net.dries007.tfc.common.blocks;

import java.util.Random;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CandleBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;

import net.dries007.tfc.common.blockentities.TickCounterBlockEntity;
import net.dries007.tfc.common.items.TFCItems;
Expand Down Expand Up @@ -69,5 +71,4 @@ public void randomTick(BlockState state, ServerLevel level, BlockPos pos, Random
{
onRandomTick(state, level, pos);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
Expand All @@ -31,8 +32,9 @@
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

import net.dries007.tfc.common.items.CandleBlockItem;
import net.dries007.tfc.common.blockentities.TickCounterBlockEntity;
import net.dries007.tfc.common.items.TFCItems;
import net.dries007.tfc.util.Helpers;

Expand Down Expand Up @@ -149,5 +151,4 @@ public ExtendedProperties getExtendedProperties()
{
return properties;
}

}
Loading