Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(LIGHTING, CANDLES);
builder.add(LIGHTING, CANDLES, POWERED);
}

@Nullable
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/twilightforest/block/BurntThornsBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.InsideBlockEffectApplier;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -15,7 +17,6 @@
import org.jspecify.annotations.Nullable;

public class BurntThornsBlock extends ThornsBlock {

public BurntThornsBlock(Properties properties) {
super(properties);
}
Expand All @@ -27,15 +28,15 @@ public PathType getBlockPathType(BlockState state, BlockGetter getter, BlockPos
}

@Override
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity, InsideBlockEffectApplier effectApplier, boolean isPrecise) {
// dissolve
if (!level.isClientSide() && (entity instanceof LivingEntity || entity instanceof Projectile)) {
level.destroyBlock(pos, false);
}
}

@Override
public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, ItemStack toolStack, boolean willHarvest, FluidState fluid) {
state.getBlock().playerWillDestroy(level, pos, state, player);
return level.setBlock(pos, fluid.createLegacyBlock(), level.isClientSide() ? Block.UPDATE_ALL_IMMEDIATE : Block.UPDATE_ALL);
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/twilightforest/block/GenericModelLoader.java
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package twilightforest.block;

import com.google.common.base.Supplier;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import net.minecraft.client.resources.model.UnbakedModel;
import net.neoforged.neoforge.client.model.UnbakedModelLoader;

public class GenericModelLoader<T extends UnbakedModel> implements UnbakedModelLoader<T> {

private final Supplier<T> modelFactory;

public GenericModelLoader(Supplier<T> modelFactory) {
this.modelFactory = modelFactory;
}

@Override
public T read(JsonObject jsonObject, JsonDeserializationContext deserializationContext) throws JsonParseException {
return this.modelFactory.get();
}
}
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
1 change: 0 additions & 1 deletion src/main/java/twilightforest/block/GiantBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.jspecify.annotations.Nullable;

public class GiantBlock extends Block {

private boolean isSelfDestructing;

public GiantBlock(Properties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import twilightforest.init.TFSounds;

public class LockedVanishingBlock extends VanishingBlock {

public static final BooleanProperty LOCKED = BooleanProperty.create("locked");

public LockedVanishingBlock(Properties properties) {
Expand Down
82 changes: 65 additions & 17 deletions src/main/java/twilightforest/block/MasonJarBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.common.world.AuxiliaryLightManager;
import net.neoforged.neoforge.transfer.item.ItemResource;
import net.neoforged.neoforge.transfer.transaction.Transaction;
import twilightforest.block.entity.MasonJarBlockEntity;
import twilightforest.init.TFSounds;

Expand All @@ -35,7 +37,6 @@
public class MasonJarBlock extends JarBlock implements SimpleWaterloggedBlock {
public static final MapCodec<MasonJarBlock> CODEC = simpleCodec(MasonJarBlock::new);
private static final int SLOT = 0;
private static final int ALL = Integer.MAX_VALUE;

public MasonJarBlock(BlockBehaviour.Properties properties) {
super(properties);
Expand Down Expand Up @@ -67,37 +68,84 @@ protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level l
}

private static void handleEmptyHand(ServerLevel server, BlockPos pos, Player player, InteractionHand hand, MasonJarBlockEntity jar, MasonJarBlockEntity.MasonJarItemStackHandler handler) {
ItemStack preview = handler.extractItem(SLOT, ALL, true);
if (preview.isEmpty()) {
wiggle(server, pos, jar);
return;
int maxAmount = 64;

ItemStack extractedStack = ItemStack.EMPTY;

try (Transaction _ = Transaction.openRoot()) {
ItemResource resource = handler.getResource(SLOT);
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated

if (!resource.isEmpty()) {
ItemStack preview = resource.toStack(handler.getAmountAsInt(SLOT));

if (player.isSecondaryUseActive()) {
player.sendOverlayMessage(Component.literal(preview.getHoverName().getString() + " x" + preview.getCount()));
wiggle(server, pos, jar);
return;
}

extractedStack = resource.toStack(0);
}
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
}
if (player.isSecondaryUseActive()) {
player.sendOverlayMessage(Component.literal(preview.getHoverName().getString() + " x" + preview.getCount()));

if (extractedStack.isEmpty()) {
wiggle(server, pos, jar);
return;
}
ItemStack extracted = handler.extractItem(SLOT, ALL, false);
player.setItemInHand(hand, extracted);
server.playSound(null, pos, TFSounds.JAR_REMOVE.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
server.gameEvent(player, GameEvent.BLOCK_CHANGE, pos);

try (Transaction transaction = Transaction.openRoot()) {
ItemResource resourceToExtract = ItemResource.of(extractedStack);
int countExtracted = handler.extract(SLOT, resourceToExtract, maxAmount, transaction);

if (countExtracted > 0) {
extractedStack.setCount(countExtracted);
transaction.commit();
player.setItemInHand(hand, extractedStack);
server.playSound(null, pos, TFSounds.JAR_REMOVE.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
server.gameEvent(player, GameEvent.BLOCK_CHANGE, pos);
return;
}
}

wiggle(server, pos, jar);
}

private static void handleInsert(ServerLevel server, BlockPos pos, Player player, InteractionHand hand, MasonJarBlockEntity jar, MasonJarBlockEntity.MasonJarItemStackHandler handler, ItemStack stack) {
// Simulate insert first; if nothing would go in then just wiggle
if (handler.insertItem(SLOT, stack, true).getCount() >= stack.getCount()) {
if (stack.isEmpty()) return;

Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
ItemResource resource = ItemResource.of(stack);
int amountToInsert = stack.getCount();
int simulatedInserted;

try (Transaction transaction = Transaction.openRoot()) {
simulatedInserted = handler.insert(SLOT, resource, amountToInsert, transaction);
}

if (simulatedInserted <= 0) {
wiggle(server, pos, jar);
return;
}

int realInserted;
try (Transaction transaction = Transaction.openRoot()) {
realInserted = handler.insert(SLOT, resource, amountToInsert, transaction);
if (realInserted > 0) {
transaction.commit();
}
}
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated

jar.setItemRotation(RotationSegment.convertToSegment(player.getYRot() + 180.0F));
player.awardStat(Stats.ITEM_USED.get(stack.getItem()));

ItemStack before = stack.copy();
ItemStack remainder = handler.insertItem(SLOT, stack, false);

ItemStack remainder = stack.copy();
remainder.shrink(realInserted);
player.setItemInHand(hand, player.hasInfiniteMaterials() ? before : remainder);
float filledRatio = (float) (before.getCount() - remainder.getCount()) / (float) before.getMaxStackSize();
server.playSound(null, pos, TFSounds.JAR_INSERT.get(), SoundSource.BLOCKS, 1.0F, 0.7F + 0.5F * filledRatio);
server.gameEvent(player, GameEvent.BLOCK_CHANGE, pos);

float filledRatio = (float) realInserted / (float) before.getMaxStackSize();
server.playSound(null, pos, TFSounds.JAR_INSERT.get(), net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 0.7F + 0.5F * filledRatio);
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
server.gameEvent(player, net.minecraft.world.level.gameevent.GameEvent.BLOCK_CHANGE, pos);
}
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated

private static void wiggle(ServerLevel server, BlockPos pos, MasonJarBlockEntity jar) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/twilightforest/block/SortLogCoreBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.neoforged.neoforge.transfer.item.ItemResource;
import net.neoforged.neoforge.transfer.transaction.Transaction;
import twilightforest.config.TFConfig;
import twilightforest.init.TFItems;
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
import twilightforest.init.TFParticleType;
import twilightforest.network.ParticlePacket;
import twilightforest.tags.TFEntityTypeTags;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/twilightforest/block/TFPortalBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

// KelpBlock seems to use ILiquidContainer as it's a block that permanently has water, so I suppose in best practices we also use this interface as well?
public class TFPortalBlock extends HalfTransparentBlock implements LiquidBlockContainer, Portal {

public static final BooleanProperty DISALLOW_RETURN = BooleanProperty.create("is_one_way");
public static final Component PORTAL_UNWORTHY = Component.translatable("misc.twilightforest.portal_unworthy");
private static final VoxelShape AABB = Shapes.create(new AABB(0.0F, 0.0F, 0.0F, 1.0F, 0.8125F, 1.0F));
Expand Down Expand Up @@ -158,7 +157,6 @@ public boolean tryToCreatePortal(ServerLevel level, BlockPos pos, ItemEntity cat
MutableInt size = new MutableInt(0);

if (recursivelyValidatePortal(level, pos, blocksChecked, size, state) && size.intValue() >= MIN_PORTAL_SIZE) {

if (!TFConfig.checkPortalPlacement) {
boolean checkProgression = LandmarkUtil.isProgressionEnforced(level);
if (!TFTeleporter.isSafeAround(level, pos, catalyst, checkProgression)) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/twilightforest/block/TrophyPedestalBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
Expand Down Expand Up @@ -92,7 +93,7 @@ protected void neighborChanged(BlockState state, Level level, BlockPos pos, Bloc
level.updateNeighbourForOutputSignal(pos, this);
if (level.isClientSide() || state.getValue(ACTIVE) || !isTrophyOnTop(level, pos)) return;

if (LandmarkUtil.isProgressionEnforced(level)) {
if (LandmarkUtil.isProgressionEnforced((ServerLevel) level)) {
if (this.areNearbyPlayersEligible(level, pos)) {
this.doPedestalEffect(level, pos, state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import twilightforest.inventory.UncraftingMenu;

public class UncraftingTableBlock extends Block {

public static final BooleanProperty POWERED = BlockStateProperties.POWERED;

public UncraftingTableBlock(BlockBehaviour.Properties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,59 +169,4 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() {
public CompoundTag getUpdateTag(HolderLookup.Provider registries) {
return this.saveCustomOnly(registries);
}

//Based From MasonJarBlockEntity class's MasonJarItemStackHandler
public static class DryingRackHandler extends ItemStacksResourceHandler {
protected final DryingRackBlockEntity inventory;

public DryingRackHandler(DryingRackBlockEntity blockEntity) {
super(1);
this.inventory = blockEntity;
}

// Used for simple checks of what the one item is, without going through all the hoops. Used by the renderer and when saving contents to item
public ItemStack getItem() {
return this.stacks.getFirst().copy();
}

// Peeks at the stored item, without cloning it
private ItemStack peekItem() {
return this.stacks.getFirst();
}

// Used when syncing to client and when placing a jar that already has stored items
public void setItem(ItemStack itemStack) {
this.stacks.set(0, itemStack);
}

@Override
public boolean isValid(int index, ItemResource resource) {
return resource.toStack().canFitInsideContainerItems();
}

@Override
public int extract(int index, ItemResource resource, int amount, TransactionContext transaction) {
if (this.inventory.drying) {
return 0;
}
int extracted = super.extract(index, resource, amount, transaction);
if (extracted > 0) {
this.inventory.setChanged();
}
return extracted;
}

@Override
public int insert(int index, ItemResource resource, int amount, TransactionContext transaction) {
int inserted = super.insert(index, resource, amount, transaction);
if (inserted > 0) {
this.inventory.setChanged();
}
return inserted;
}

public boolean isEmpty() {
return this.stacks.getFirst().isEmpty();
}
}
Comment thread
Sleepy-Horse marked this conversation as resolved.
}
Loading