-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
519 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
- Added Item Packer: | ||
- New block that allows you to add and remove items from Shulker Boxes, bundles and any other storage api compatible item! | ||
- You place/remove the storage item by adding it in front/back of the block. | ||
- All other sides can add/remove items from item's inventory. | ||
- Made out of | ||
- Increased damage done by Lava Splash to 2 hearts (from 0.5). | ||
- Increased damage done by Experience Splash x2 (compared to previously). | ||
- Recipes now use Fabric's Convention tag for Stripped Logs | ||
- Recipes now use Fabric's Convention tag for Stripped Logs. | ||
- Fix Funnels pulling items form blocks using Fabric Storage API loosing last stack if the storage becomes empty. | ||
- Fix Conveyors sometimes deleting items. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
src/main/java/eu/pb4/polyfactory/block/other/ItemPackerBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
package eu.pb4.polyfactory.block.other; | ||
|
||
import eu.pb4.factorytools.api.block.BarrierBasedWaterloggable; | ||
import eu.pb4.factorytools.api.block.FactoryBlock; | ||
import eu.pb4.factorytools.api.virtualentity.BlockModel; | ||
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil; | ||
import eu.pb4.polyfactory.util.FactoryUtil; | ||
import eu.pb4.polymer.virtualentity.api.ElementHolder; | ||
import eu.pb4.polymer.virtualentity.api.attachment.BlockBoundAttachment; | ||
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment; | ||
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.fluid.FluidState; | ||
import net.minecraft.fluid.Fluids; | ||
import net.minecraft.inventory.SidedInventory; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.ModelTransformationMode; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.EnumProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.*; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldAccess; | ||
import net.minecraft.world.WorldView; | ||
import net.minecraft.world.tick.ScheduledTickView; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.joml.Matrix4fStack; | ||
import xyz.nucleoid.packettweaker.PacketContext; | ||
|
||
|
||
public class ItemPackerBlock extends Block implements FactoryBlock, BlockEntityProvider, BarrierBasedWaterloggable, InventoryProvider { | ||
public static EnumProperty<Direction> FACING = Properties.FACING; | ||
|
||
public ItemPackerBlock(Settings settings) { | ||
super(settings); | ||
this.setDefaultState(this.getDefaultState().with(WATERLOGGED, false)); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
super.appendProperties(builder); | ||
builder.add(FACING); | ||
builder.add(WATERLOGGED); | ||
} | ||
|
||
@Override | ||
protected BlockState getStateForNeighborUpdate(BlockState state, WorldView world, ScheduledTickView tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, Random random) { | ||
tickWater(state, world, tickView, pos); | ||
return super.getStateForNeighborUpdate(state, world, tickView, pos, direction, neighborPos, neighborState, random); | ||
} | ||
|
||
@Override | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { | ||
if (world.getBlockEntity(pos) instanceof ItemPackerBlockEntity be && player instanceof ServerPlayerEntity serverPlayer) { | ||
be.openGui(serverPlayer); | ||
return ActionResult.SUCCESS_SERVER; | ||
} | ||
|
||
return super.onUse(state, world, pos, player, hit); | ||
} | ||
|
||
@Override | ||
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { | ||
if (!state.isOf(newState.getBlock())) { | ||
if (world.getBlockEntity(pos) instanceof ItemPackerBlockEntity be) { | ||
ItemScatterer.spawn(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, be.getStack()); | ||
world.updateComparators(pos, this); | ||
} | ||
} | ||
super.onStateReplaced(state, world, pos, newState, moved); | ||
|
||
} | ||
|
||
@Override | ||
public boolean hasComparatorOutput(BlockState state) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getComparatorOutput(BlockState state, World world, BlockPos pos) { | ||
if (world.getBlockEntity(pos) instanceof ItemPackerBlockEntity be) { | ||
return (int) ((be.getFilledAmount() * 15) / Math.max(be.getFillCapacity(), 1)); | ||
} | ||
return 0; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return waterLog(ctx, this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite())); | ||
} | ||
|
||
@Override | ||
public FluidState getFluidState(BlockState state) { | ||
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); | ||
} | ||
|
||
@Override | ||
public BlockState rotate(BlockState state, BlockRotation rotation) { | ||
return FactoryUtil.transform(state, rotation::rotate, FACING); | ||
} | ||
|
||
@Override | ||
public BlockState mirror(BlockState state, BlockMirror mirror) { | ||
return FactoryUtil.transform(state, mirror::apply, FACING); | ||
} | ||
|
||
@Override | ||
public BlockState getPolymerBreakEventBlockState(BlockState state, PacketContext context) { | ||
return Blocks.OAK_PLANKS.getDefaultState(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new ItemPackerBlockEntity(pos, state); | ||
} | ||
|
||
@Override | ||
public ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) { | ||
return new Model(world, pos, initialBlockState); | ||
} | ||
|
||
@Override | ||
public SidedInventory getInventory(BlockState state, WorldAccess world, BlockPos pos) { | ||
return null; | ||
} | ||
|
||
public final class Model extends BlockModel { | ||
private final Matrix4fStack mat = new Matrix4fStack(2); | ||
private final ItemDisplayElement mainElement; | ||
private final ItemDisplayElement itemElement; | ||
|
||
private Model(ServerWorld world, BlockPos pos, BlockState state) { | ||
this.mainElement = ItemDisplayElementUtil.createSimple(ItemPackerBlock.this.asItem()); | ||
|
||
this.itemElement = ItemDisplayElementUtil.createSimple(); | ||
this.itemElement.setDisplaySize(1, 1); | ||
this.itemElement.setModelTransformation(ModelTransformationMode.NONE); | ||
this.itemElement.setViewRange(0.4f); | ||
|
||
//this.countElement.setShadow(true); | ||
|
||
this.updateFacing(state); | ||
this.addElement(this.mainElement); | ||
this.addElement(this.itemElement); | ||
} | ||
|
||
public void setDisplay(ItemStack stack) { | ||
this.itemElement.setItem(stack.copy()); | ||
this.tick(); | ||
} | ||
|
||
private void updateFacing(BlockState facing) { | ||
var rot = facing.get(FACING).getRotationQuaternion().mul(Direction.NORTH.getRotationQuaternion()); | ||
mat.clear(); | ||
mat.rotate(rot); | ||
mat.pushMatrix(); | ||
mat.rotateY(MathHelper.PI); | ||
mat.scale(2f); | ||
this.mainElement.setTransformation(mat); | ||
mat.popMatrix(); | ||
|
||
mat.pushMatrix(); | ||
//mat.translate(0, 1f / 16f, -6.2f / 16f); | ||
mat.scale(10 / 16f); | ||
this.itemElement.setTransformation(mat); | ||
mat.popMatrix(); | ||
this.tick(); | ||
} | ||
|
||
@Override | ||
public void notifyUpdate(HolderAttachment.UpdateType updateType) { | ||
if (updateType == BlockBoundAttachment.BLOCK_STATE_UPDATE) { | ||
this.updateFacing(this.blockState()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.