Skip to content

Commit

Permalink
add lunar flag and mossy variants
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Sep 19, 2024
1 parent f12dd8a commit d3b3e2c
Show file tree
Hide file tree
Showing 28 changed files with 536 additions and 3 deletions.
57 changes: 57 additions & 0 deletions src/main/java/ru/pinkgoosik/hiddenrealm/block/LunarFlagBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ru.pinkgoosik.hiddenrealm.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;

public class LunarFlagBlock extends Block {
public static final EnumProperty<Direction.Axis> AXIS = Properties.HORIZONTAL_AXIS;

private static final VoxelShape X_SHAPE = createXShape();
private static final VoxelShape Z_SHAPE = createZShape();

public LunarFlagBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(AXIS, Direction.Axis.X));
}

private static VoxelShape createZShape() {
VoxelShape shape = VoxelShapes.empty();
shape = VoxelShapes.combine(shape, VoxelShapes.cuboid(0.4375, 0.6875, 0, 0.5625, 0.875, 1), BooleanBiFunction.OR);
return shape;
}

private static VoxelShape createXShape() {
VoxelShape shape = VoxelShapes.empty();
shape = VoxelShapes.combine(shape, VoxelShapes.cuboid(0, 0.6875, 0.4375, 1, 0.875, 0.5625), BooleanBiFunction.OR);
return shape;
}

@Override
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return state.get(AXIS).equals(Direction.Axis.Z) ? Z_SHAPE : X_SHAPE;
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(AXIS);
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
if(ctx.getSide().getAxis().isHorizontal()) {
return this.getDefaultState().with(AXIS, ctx.getSide().getAxis());
}
else return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public Identifier getTexture(Entity entity) {

BlockRenderLayerMap.INSTANCE.putBlock(HiddenRealmBlocks.BOTTLE_WISP, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(HiddenRealmBlocks.BAZAAR_LAMP, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(HiddenRealmBlocks.LUNAR_FLAG, RenderLayer.getCutout());
}

private static void onHudRender(DrawContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ru.pinkgoosik.hiddenrealm.extension;

public interface LivingEntityExtension {
boolean isBeheaded();
void setBeheaded(boolean isBeheaded);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.pinkgoosik.hiddenrealm.mixin;

import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.entity.model.AnimalModel;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.client.render.entity.model.ModelWithArms;
import net.minecraft.client.render.entity.model.ModelWithHead;
import net.minecraft.entity.LivingEntity;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.pinkgoosik.hiddenrealm.extension.LivingEntityExtension;

@Mixin(BipedEntityModel.class)
abstract class BipedEntityModelMixin<T extends LivingEntity> extends AnimalModel<T> implements ModelWithArms, ModelWithHead {

@Shadow
@Final
public ModelPart head;

@Inject(method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V", at = @At("HEAD"))
void setAngles(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
if(livingEntity instanceof LivingEntityExtension ex) {
head.visible = !ex.isBeheaded();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ru.pinkgoosik.hiddenrealm.mixin;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.pinkgoosik.hiddenrealm.extension.LivingEntityExtension;
import ru.pinkgoosik.hiddenrealm.registry.HiddenRealmItems;

@Mixin(LivingEntity.class)
abstract class LivingEntityMixin extends Entity implements LivingEntityExtension {

private static final TrackedData<Boolean> BEHEADED = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.BOOLEAN);

public LivingEntityMixin(EntityType<?> type, World world) {
super(type, world);
}

@Inject(method = "writeCustomDataToNbt", at = @At(value = "TAIL"))
public void writeCustomDataToNBT(NbtCompound nbt, CallbackInfo ci){
nbt.putBoolean("Beheaded", this.isBeheaded());
}

@Inject(method = "readCustomDataFromNbt", at = @At(value = "TAIL"))
public void readCustomDataToNBT(NbtCompound nbt, CallbackInfo ci){
this.setBeheaded(nbt.getBoolean("Beheaded"));
}

@Inject(method = "initDataTracker", at = @At(value = "TAIL"))
public void initDataTracker(DataTracker.Builder builder, CallbackInfo ci) {
builder.add(BEHEADED, false);
}

@Inject(method = "damage", at = @At("HEAD"))
void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {

if(source.getAttacker() instanceof PlayerEntity player) {
if(player.getStackInHand(Hand.MAIN_HAND).isOf(HiddenRealmItems.BEHEADING_KATANA) && !isBeheaded()) {
setBeheaded(true);
dropStack(Items.ZOMBIE_HEAD.getDefaultStack());
}
}
}

@Override
public boolean isBeheaded() {
return dataTracker.get(BEHEADED);
}

@Override
public void setBeheaded(boolean isBeheaded) {
dataTracker.set(BEHEADED, isBeheaded);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ public class HiddenRealmBlocks {

public static final Block BAZAAR_PORTAL_PAD = add("bazaar_portal_pad", new BazaarPortalPadBlock(copy(Blocks.BEDROCK).ticksRandomly()));
public static final Block BAZAAR_PORTAL = add("bazaar_portal", new BazaarPortalBlock(copy(Blocks.BEDROCK)));
public static final Block TRADING_PEDESTAL = add("trading_pedestal", new TradingPedestalBlock(copy(Blocks.BEDROCK).nonOpaque().notSolid()));
public static final Block REFRESHER = add("refresher", new RefresherBlock(copy(Blocks.STONE).nonOpaque().notSolid()));
public static final Block TRADING_PEDESTAL = add("trading_pedestal", new TradingPedestalBlock(copy(Blocks.BEDROCK).nonOpaque()));
public static final Block REFRESHER = add("refresher", new RefresherBlock(copy(Blocks.STONE).nonOpaque()));
public static final Block LUNAR_FLAG = add("lunar_flag", new LunarFlagBlock(copy(Blocks.OAK_PLANKS).nonOpaque()));

public static final Block MOONSTONE_BRICKS = add("moonstone_bricks", new Block(copy(Blocks.STONE_BRICKS)));
public static final Block MOONSTONE_BRICK_STAIRS = add("moonstone_brick_stairs", new StairsBlock(MOONSTONE_BRICKS.getDefaultState(), copy(Blocks.STONE_BRICKS)));
public static final Block MOONSTONE_BRICK_SLAB = add("moonstone_brick_slab", new SlabBlock(copy(Blocks.STONE_BRICKS)));
public static final Block MOSSY_MOONSTONE_BRICKS = add("mossy_moonstone_bricks", new Block(copy(Blocks.STONE_BRICKS)));
public static final Block MOSSY_MOONSTONE_BRICK_STAIRS = add("mossy_moonstone_brick_stairs", new StairsBlock(MOSSY_MOONSTONE_BRICKS.getDefaultState(), copy(Blocks.STONE_BRICKS)));
public static final Block MOSSY_MOONSTONE_BRICK_SLAB = add("mossy_moonstone_brick_slab", new SlabBlock(copy(Blocks.STONE_BRICKS)));
public static final Block CHISELED_MOONSTONE_BRICKS = add("chiseled_moonstone_bricks", new Block(copy(Blocks.STONE_BRICKS).luminance(state -> 10)));
public static final Block BOTTLE_WISP = add("bottle_wisp", new BottleWispBlock(copy(Blocks.GLASS).sounds(BlockSoundGroup.LANTERN).nonOpaque().luminance(state -> 15).pistonBehavior(PistonBehavior.DESTROY)));
public static final Block LUNAR_MUSHROOM = add("lunar_mushroom", new LunarMushroomBlock(copy(Blocks.BROWN_MUSHROOM).sounds(BlockSoundGroup.FUNGUS).pistonBehavior(PistonBehavior.DESTROY)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class HiddenRealmItems {
public static final Item LUNAR_COIN = add("lunar_coin", new LunarCoinItem(new Item.Settings()));
public static final Item FIRE_BOOTS = add("fire_boots", new FireBootsItem(new Item.Settings().fireproof().maxCount(1)));

public static final Item BEHEADING_KATANA = add("beheading_katana", new Item(new Item.Settings().maxCount(1)));

public static final Item EXPERIENCE_NECKLACE = add("experience_necklace", new Item(new Item.Settings().maxCount(1).maxDamage(100)));

public static final ItemGroup ITEM_GROUP = FabricItemGroup.builder()
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/assets/hiddenrealm/blockstates/lunar_flag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"variants": {
"axis=x": {
"model": "hiddenrealm:block/lunar_flag"
},
"axis=z": {
"model": "hiddenrealm:block/lunar_flag",
"y": 90
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"variants": {
"type=bottom": {
"model": "hiddenrealm:block/mossy_moonstone_brick_slab"
},
"type=double": {
"model": "hiddenrealm:block/mossy_moonstone_bricks"
},
"type=top": {
"model": "hiddenrealm:block/mossy_moonstone_brick_slab_top"
}
}
}
Loading

0 comments on commit d3b3e2c

Please sign in to comment.