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

Holopad-focused code cleanup #623

Merged
merged 12 commits into from
Sep 26, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Perfectly generic and cindered signs work again
- Fixed execution permissions for the `minestuck:command` dialogue trigger
- Add missing wood-related recipes
- Updated holopad collision shape
- The block model for the holopad with card now renders with cutout

### Contributors for this release

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,6 @@
"entity.minestuck.giclops.type": "%s Giclops",
"entity.minestuck.grist": "Grist",
"entity.minestuck.grist.type": "%s Grist",
"entity.minestuck.hologram": "Hologram",
"entity.minestuck.iguana": "Iguana",
"entity.minestuck.iguana.plural": "Iguanas",
"entity.minestuck.iguana.sound": "Thip",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mraof.minestuck.block.machine;

import com.mraof.minestuck.block.CustomVoxelShape;
import com.mraof.minestuck.block.MSBlockShapes;
import com.mraof.minestuck.block.MSProperties;
import com.mraof.minestuck.blockentity.ComputerBlockEntity;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class ComputerBlock extends MachineBlock implements EntityBlock
public static final Map<Direction, VoxelShape> COMPUTER_SHAPE = MSBlockShapes.COMPUTER.createRotatedShapes();
public static final Map<Direction, VoxelShape> LAPTOP_CLOSED_SHAPE = MSBlockShapes.LAPTOP_CLOSED.createRotatedShapes();
public static final Map<Direction, VoxelShape> LAPTOP_OPEN_SHAPE = MSBlockShapes.LAPTOP_OPEN.createRotatedShapes();
public static final Map<Direction, VoxelShape> LUNCHTOP_CLOSED_SHAPE = createRotatedShapes(4, 0, 1.5, 12, 5, 8.5);
public static final Map<Direction, VoxelShape> LUNCHTOP_CLOSED_SHAPE = new CustomVoxelShape(new double[]{4, 0, 1.5, 12, 5, 8.5}).createRotatedShapes();
public static final Map<Direction, VoxelShape> LUNCHTOP_OPEN_SHAPE = MSBlockShapes.LUNCHTOP_OPEN.createRotatedShapes();
public static final Map<Direction, VoxelShape> OLD_COMPUTER_SHAPE = MSBlockShapes.OLD_COMPUTER.createRotatedShapes();

Expand Down Expand Up @@ -235,4 +236,4 @@ public String getSerializedName()
return name().toLowerCase();
}
}
}
}
30 changes: 6 additions & 24 deletions src/main/java/com/mraof/minestuck/block/machine/HolopadBlock.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mraof.minestuck.block.machine;

import com.mraof.minestuck.block.BlockUtil;
import com.mraof.minestuck.block.CustomVoxelShape;
import com.mraof.minestuck.block.MSProperties;
import com.mraof.minestuck.blockentity.HolopadBlockEntity;
import com.mraof.minestuck.blockentity.MSBlockEntityTypes;
Expand All @@ -20,10 +21,8 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import javax.annotation.Nullable;
Expand All @@ -34,21 +33,13 @@
@MethodsReturnNonnullByDefault
public class HolopadBlock extends MachineBlock implements EntityBlock
{
public static final Map<Direction, VoxelShape> SHAPE = createRotatedShapes(2, 0, 1, 14, 6, 13);
public static final Map<Direction, VoxelShape> COLLISION_SHAPE;
//todo these are unused?
protected static final AABB HOLOPAD_TOP_AABB = new AABB(3/16F, 6/16F, 2.6/16F, 13/16F, 7/16F, 12.6/16F);
protected static final AABB HOLOPAD_CARDSLOT_AABB = new AABB(4/16F, 0F, 13.8/16F, 12/16F, 10.1/16F, 15.94/16F);
public static final Map<Direction, VoxelShape> SHAPE = new CustomVoxelShape(
new double[]{2, 0, 1, 14, 7, 13},
new double[]{4, 0, 13, 12, 10, 16}
).createRotatedShapes();

public static final BooleanProperty HAS_CARD = MSProperties.HAS_CARD;

static
{
VoxelShape topShape = Block.box(3, 6, 3, 13, 7, 13);
COLLISION_SHAPE = createRotatedShapes(4, 0, 14, 12, 10, 16);
COLLISION_SHAPE.replaceAll((enumFacing, shape) -> Shapes.or(shape, topShape));
}

public HolopadBlock(Properties builder)
{
super(builder);
Expand Down Expand Up @@ -108,13 +99,4 @@ public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, Co
{
return SHAPE.get(state.getValue(FACING));
}

@Override
@SuppressWarnings("deprecation")
public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context)
{
return COLLISION_SHAPE.get(state.getValue(FACING));
}


}
}
28 changes: 0 additions & 28 deletions src/main/java/com/mraof/minestuck/block/machine/MachineBlock.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.mraof.minestuck.block.machine;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.mraof.minestuck.block.CustomVoxelShape;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Mirror;
Expand All @@ -13,12 +9,8 @@
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.VoxelShape;

import javax.annotation.Nullable;
import java.util.EnumMap;
import java.util.Map;
import java.util.function.Function;

public abstract class MachineBlock extends Block
{
Expand Down Expand Up @@ -63,24 +55,4 @@ public BlockState mirror(BlockState state, Mirror mirrorIn)
return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
}

public static Map<Direction, VoxelShape> createRotatedShapes(CustomVoxelShape shape)
{
return Maps.newEnumMap(ImmutableMap.of(Direction.NORTH, shape.create(Direction.NORTH), Direction.SOUTH, shape.create(Direction.SOUTH), Direction.WEST, shape.create(Direction.WEST), Direction.EAST, shape.create(Direction.EAST)));
}

public static Map<Direction, VoxelShape> createRotatedShapes(double x1, double y1, double z1, double x2, double y2, double z2)
{
return Maps.newEnumMap(ImmutableMap.of(Direction.NORTH, Block.box(x1, y1, z1, x2, y2, z2), Direction.SOUTH, Block.box(16 - x2, y1, 16 - z2, 16 - x1, y2, 16 - z1),
Direction.WEST, Block.box(z1, y1, 16 - x2, z2, y2, 16 - x1), Direction.EAST, Block.box(16 - z2, y1, x1, 16 - z1, y2, x2)));
}

public static <K extends Enum<K>, V> Map<K, V> createEnumMapping(Class<K> c, K[] keys, Function<K, V> function)
{
EnumMap<K, V> map = Maps.newEnumMap(c);
for(K k : keys)
{
map.put(k, function.apply(k));
}
return Maps.immutableEnumMap(map);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.mraof.minestuck.blockentity;

import com.mraof.minestuck.alchemy.AlchemyHelper;
import com.mraof.minestuck.block.MSBlocks;
import com.mraof.minestuck.block.machine.HolopadBlock;
import com.mraof.minestuck.item.MSItems;
import com.mraof.minestuck.alchemy.AlchemyHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -21,9 +21,8 @@

public class HolopadBlockEntity extends BlockEntity
{

public int innerRotation = 0;
protected ItemStack card = ItemStack.EMPTY;
private int rotationTicks = 0;
private ItemStack card = ItemStack.EMPTY;
kirderf1 marked this conversation as resolved.
Show resolved Hide resolved

public HolopadBlockEntity(BlockPos pos, BlockState state)
{
Expand All @@ -33,33 +32,30 @@ public HolopadBlockEntity(BlockPos pos, BlockState state)
public void onRightClick(Player player)
{
if(!card.isEmpty())
{
if (player.getMainHandItem().isEmpty())
player.setItemInHand(InteractionHand.MAIN_HAND, card);
else if (!player.getInventory().add(card))
dropItem(false, level, worldPosition, card);
else player.inventoryMenu.broadcastChanges();

setCard(ItemStack.EMPTY);
return;
}
takeItem(player);
else
insertHeldItem(player);
}

private void takeItem(Player player)
{
if(player.getMainHandItem().isEmpty())
player.setItemInHand(InteractionHand.MAIN_HAND, card);
else if(!player.getInventory().add(card))
dropItem(false, level, worldPosition, card);
else player.inventoryMenu.broadcastChanges();

this.card = ItemStack.EMPTY;
updateState();
}

private void insertHeldItem(Player player)
{
ItemStack heldStack = player.getMainHandItem();
if(card.isEmpty() && !heldStack.isEmpty() && heldStack.is(MSItems.CAPTCHA_CARD))
{
ItemStack heldStack = player.getMainHandItem();
if (card.isEmpty())
{
if (!heldStack.isEmpty() && heldStack.getItem() == MSItems.CAPTCHA_CARD.get())
{
setCard(heldStack.split(1)); //Insert card into the card slot
ItemStack in = getCard();
ItemStack item = new ItemStack(MSBlocks.GENERIC_OBJECT.get());

if (in.hasTag() && in.getTag().contains("contentID"))
item = AlchemyHelper.getDecodedItem(in);
}


}
this.card = heldStack.split(1);
updateState();
}
}

Expand All @@ -73,55 +69,37 @@ else if(!Block.canSupportCenter(level, pos.above(), Direction.DOWN))
else dropPos = pos;

Containers.dropItemStack(level, dropPos.getX(), dropPos.getY(), dropPos.getZ(), item);

}

public boolean hasCard()
{
return !this.getCard().isEmpty();
}

public void setCard(ItemStack card)
{
if (card.getItem() == MSItems.CAPTCHA_CARD.get() || card.isEmpty())
{
this.card = card;
if(level != null)
{
updateState();
}
}
}

public ItemStack getCard()
{
return this.card;
}

public ItemStack getHoloItem()
{
ItemStack in = getCard();
ItemStack item = new ItemStack(MSBlocks.GENERIC_OBJECT.get());

if (in.hasTag() && in.getTag().contains("contentID"))
item = AlchemyHelper.getDecodedItem(in);
if(!AlchemyHelper.isPunchedCard(this.card))
return new ItemStack(MSBlocks.GENERIC_OBJECT);

return item;
return AlchemyHelper.getDecodedItem(this.card);
}

@Override
public void load(CompoundTag nbt)
{
super.load(nbt);
//broken = tagCompound.getBoolean("broken");
setCard(ItemStack.of(nbt.getCompound("card")));
this.card = ItemStack.of(nbt.getCompound("card"));
}

@Override
public void saveAdditional(CompoundTag compound)
{
super.saveAdditional(compound);
//tagCompound.setBoolean("broken", this.broken);
compound.put("card", card.save(new CompoundTag()));
}

Expand All @@ -139,9 +117,14 @@ public Packet<ClientGamePacketListener> getUpdatePacket()
return ClientboundBlockEntityDataPacket.create(this);
}

public int getRotationTickForRender()
{
return this.rotationTicks;
}

public static void clientTick(Level level, BlockPos pos, BlockState state, HolopadBlockEntity blockEntity)
{
blockEntity.innerRotation++;
blockEntity.rotationTicks++;
}

private void updateState()
Expand All @@ -154,4 +137,4 @@ private void updateState()
level.setBlock(worldPosition, state.setValue(HolopadBlock.HAS_CARD, hasCard), Block.UPDATE_CLIENTS);
}
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/mraof/minestuck/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public static void registerKeyMappings(RegisterKeyMappingsEvent event)
public static void init(final FMLClientSetupEvent event)
{
EntityRenderers.register(MSEntityTypes.FROG.get(), FrogRenderer::new);
EntityRenderers.register(MSEntityTypes.HOLOGRAM.get(), HologramRenderer::new);
EntityRenderers.register(MSEntityTypes.LOTUS_FLOWER.get(), LotusFlowerRenderer::new);
EntityRenderers.register(MSEntityTypes.SERVER_CURSOR.get(), ServerCursorRenderer::new);
EntityRenderers.register(MSEntityTypes.NAKAGATOR.get(), context -> new ConsortRenderer<>(context, EnumConsort.NAKAGATOR));
Expand Down Expand Up @@ -184,4 +183,4 @@ public static Player getClientPlayer()
Minecraft mc = Minecraft.getInstance();
return mc.player;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public void render(HolopadBlockEntity blockEntityIn, float partialTicks, PoseSta
if(blockEntityIn.hasCard())
{
ItemStack item = blockEntityIn.getHoloItem();
float f = (float) blockEntityIn.innerRotation + partialTicks;
poseStack.pushPose();
poseStack.translate(0.5F, 0.6F, 0.5F);
poseStack.mulPose(Axis.YP.rotation((f / 20.0F * 57.295776F) / 75));
poseStack.mulPose(Axis.YP.rotation(((float) blockEntityIn.getRotationTickForRender() + partialTicks) / 20.0F));
Minecraft.getInstance().getItemRenderer().renderStatic(item, ItemDisplayContext.GROUND, combinedLightIn, combinedOverlayIn, poseStack, bufferIn, blockEntityIn.getLevel(), (int)blockEntityIn.getBlockPos().asLong());
poseStack.popPose();
}
Expand Down

This file was deleted.

Loading