Skip to content

Commit

Permalink
Icing WIP, Gingerbread Man tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Dec 7, 2024
1 parent 500173d commit b10f057
Show file tree
Hide file tree
Showing 22 changed files with 329 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.starfish_studios.seasons_greetings.block;

import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import org.jetbrains.annotations.NotNull;

import java.util.function.ToIntFunction;

public class IcingBlock extends MultifaceBlock implements SimpleWaterloggedBlock {
public static final MapCodec<IcingBlock> CODEC = simpleCodec(IcingBlock::new);
private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
private final MultifaceSpreader spreader = new MultifaceSpreader(this);

@Override
public @NotNull MapCodec<IcingBlock> codec() {
return CODEC;
}

public IcingBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState(this.defaultBlockState().setValue(WATERLOGGED, Boolean.FALSE));
}

public static ToIntFunction<BlockState> emission(int i) {
return blockState -> MultifaceBlock.hasAnyFace(blockState) ? i : 0;
}

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

@Override
protected @NotNull BlockState updateShape(
BlockState blockState, Direction direction, BlockState blockState2, LevelAccessor levelAccessor, BlockPos blockPos, BlockPos blockPos2
) {
if (blockState.getValue(WATERLOGGED)) {
levelAccessor.scheduleTick(blockPos, Fluids.WATER, Fluids.WATER.getTickDelay(levelAccessor));
}

return super.updateShape(blockState, direction, blockState2, levelAccessor, blockPos, blockPos2);
}

@Override
protected boolean canBeReplaced(BlockState blockState, BlockPlaceContext blockPlaceContext) {
return !blockPlaceContext.getItemInHand().is(this.asItem()) || super.canBeReplaced(blockState, blockPlaceContext);
}

@Override
protected @NotNull FluidState getFluidState(BlockState blockState) {
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
}

@Override
protected boolean propagatesSkylightDown(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos) {
return blockState.getFluidState().isEmpty();
}

@Override
public @NotNull MultifaceSpreader getSpreader() {
return this.spreader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static void registerRenderers() {

SGBlocks.STRING_LIGHTS,
SGBlocks.WREATH,
SGBlocks.GINGERBREAD_DOOR,

SGBlocks.WHITE_GIFT_BOX,
SGBlocks.LIGHT_GRAY_GIFT_BOX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.world.entity.ai.goal.*;
import net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal;
import net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal;
import net.minecraft.world.entity.ai.goal.target.ResetUniversalAngerTargetGoal;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.item.ItemEntity;
Expand All @@ -43,6 +44,7 @@

import java.util.EnumSet;
import java.util.Iterator;
import java.util.Objects;

public class GingerbreadMan extends TamableAnimal implements GeoEntity {
protected static final RawAnimation IDLE = RawAnimation.begin().thenLoop("animation.gingerbread_man.idle");
Expand All @@ -51,6 +53,7 @@ public class GingerbreadMan extends TamableAnimal implements GeoEntity {
protected static final RawAnimation ATTACK = RawAnimation.begin().then("animation.gingerbread_man.attack", Animation.LoopType.PLAY_ONCE);
protected static final RawAnimation ATTACK2 = RawAnimation.begin().thenPlay("animation.gingerbread_man.attack2");
protected static final RawAnimation DIE = RawAnimation.begin().thenPlayAndHold("animation.gingerbread_man.die");
protected static final RawAnimation SIT = RawAnimation.begin().thenLoop("animation.gingerbread_man.sit");

private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);

Expand Down Expand Up @@ -86,6 +89,15 @@ private void removeInteractionItem(Player player, ItemStack itemStack) {
public @NotNull InteractionResult mobInteract(Player player, InteractionHand hand) {
ItemStack itemStack = player.getItemInHand(hand);
ItemStack itemStack2 = this.getMainHandItem();
InteractionResult interactionResult = super.mobInteract(player, hand);

if (!interactionResult.consumesAction() && this.isOwnedBy(player)) {
this.setOrderedToSit(!this.isOrderedToSit());
this.jumping = false;
this.navigation.stop();
this.setTarget(null);
return InteractionResult.SUCCESS_NO_ITEM_USED;
}

if (itemStack2.isEmpty() && !itemStack.isEmpty()) {
ItemStack itemStack3 = itemStack.copyWithCount(1);
Expand Down Expand Up @@ -116,8 +128,8 @@ public boolean cantCatchMe(boolean b) {
@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor serverLevelAccessor, DifficultyInstance difficultyInstance, MobSpawnType mobSpawnType, @Nullable SpawnGroupData spawnGroupData) {
this.populateDefaultEquipmentSlots(random, difficultyInstance);
if (mobSpawnType == MobSpawnType.SPAWN_EGG || mobSpawnType == MobSpawnType.COMMAND || mobSpawnType == MobSpawnType.MOB_SUMMONED) {
cantCatchMe(false);
if (mobSpawnType == MobSpawnType.SPAWN_EGG) {
this.setOwnerUUID(Objects.requireNonNull(serverLevelAccessor.getNearestPlayer(this, 8.0D)).getUUID());
}
return super.finalizeSpawn(serverLevelAccessor, difficultyInstance, mobSpawnType, spawnGroupData);
}
Expand All @@ -139,22 +151,35 @@ public static AttributeSupplier.Builder createAttributes() {
protected void registerGoals() {
this.goalSelector.addGoal(0, new FloatGoal(this));

this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.0, true));
this.goalSelector.addGoal(1, new PanicGoal(this, 1.25));
this.goalSelector.addGoal(2, new SitWhenOrderedToGoal(this));
this.goalSelector.addGoal(3, new MeleeAttackGoal(this, 1.0, true));

this.goalSelector.addGoal(2, new PanicGoal(this, 1.25));
this.goalSelector.addGoal(3, new FollowOwnerGoal(this, 1.25, 10.0F, 2.0F));
this.goalSelector.addGoal(4, new AvoidEatingPlayerGoal(this, 8.0, 1.0, 1.2));
this.goalSelector.addGoal(4, new FollowOwnerGoal(this, 1.25, 10.0F, 2.0F));
this.goalSelector.addGoal(5, new AvoidEatingPlayerGoal(this, 8.0, 1.0, 1.2));

this.goalSelector.addGoal(5, new TemptGoal(this, 1.2, (itemStack) -> itemStack.is(Items.COOKIE), false));
this.goalSelector.addGoal(6, new CopyOwnerBreakGoal(this, 1.0));
this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0));
this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 6.0F));
this.goalSelector.addGoal(9, new RandomLookAroundGoal(this));
this.goalSelector.addGoal(6, new TemptGoal(this, 1.2, (itemStack) -> itemStack.is(Items.COOKIE), false));
this.goalSelector.addGoal(7, new CopyOwnerBreakGoal(this, 1.0));
this.goalSelector.addGoal(8, new WaterAvoidingRandomStrollGoal(this, 1.0));
this.goalSelector.addGoal(9, new LookAtPlayerGoal(this, Player.class, 6.0F));
this.goalSelector.addGoal(10, new RandomLookAroundGoal(this));

this.targetSelector.addGoal(1, new OwnerHurtByTargetGoal(this));
this.targetSelector.addGoal(2, new OwnerHurtTargetGoal(this));
}

public boolean hurt(DamageSource damageSource, float f) {
if (this.isInvulnerableTo(damageSource)) {
return false;
} else {
if (!this.level().isClientSide) {
this.setOrderedToSit(false);
}

return super.hurt(damageSource, f);
}
}

// region GeckoLib

@Override
Expand All @@ -177,7 +202,9 @@ private PlayState attackPredicate(AnimationState<?> event) {
}

private <E extends GingerbreadMan> PlayState predicate(final AnimationState<E> event) {
if (event.isMoving()) {
if (this.isOrderedToSit()) {
event.setAnimation(SIT);
} else if (event.isMoving()) {
if (this.getAttributeValue(Attributes.MOVEMENT_SPEED) == 0.25 * 1.25) {
event.setControllerSpeed(1.25F);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SGBlocks {
public static final Block GINGERBREAD_SHINGLES = registerBlock("gingerbread_shingles", new Block(gingerbreadProperties));
public static final Block GINGERBREAD_SHINGLE_STAIRS = registerBlock("gingerbread_shingle_stairs", new StairBlock(GINGERBREAD_SHINGLES.defaultBlockState(), gingerbreadProperties));
public static final Block GINGERBREAD_SHINGLE_SLAB = registerBlock("gingerbread_shingle_slab", new SlabBlock(gingerbreadProperties));
// public static final Block GINGERBREAD_DOOR = registerBlock("gingerbread_door", new DoorBlock(null, gingerbreadProperties.noOcclusion().pushReaction(PushReaction.DESTROY)));
public static final Block GINGERBREAD_DOOR = registerBlock("gingerbread_door", new DoorBlock(BlockSetType.OAK, gingerbreadProperties.noOcclusion().pushReaction(PushReaction.DESTROY)));

public static final BlockBehaviour.Properties chocolateProperties = Block.Properties.of().strength(0.3F).sound(SoundType.WOOL);
public static final Block CHOCOLATE_BLOCK = registerBlock("chocolate_block", new Block(chocolateProperties));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class SGCreativeTabs {
output.accept(CHOCOLATE_STAIRS);
output.accept(CHOCOLATE_SLAB);

output.accept(GINGERBREAD_DOOR);
output.accept(GINGERBREAD_BLOCK);
output.accept(GINGERBREAD_STAIRS);
output.accept(GINGERBREAD_SLAB);
Expand All @@ -58,6 +59,7 @@ public class SGCreativeTabs {
output.accept(GINGERBREAD_SHINGLE_STAIRS);
output.accept(GINGERBREAD_SHINGLE_SLAB);


output.accept(WHITE_GIFT_BOX);
output.accept(LIGHT_GRAY_GIFT_BOX);
output.accept(GRAY_GIFT_BOX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public class SGItems {
public static final Item GINGERBREAD_SHINGLE_STAIRS = registerItem("gingerbread_shingle_stairs", new BlockItem(SGBlocks.GINGERBREAD_SHINGLE_STAIRS, new Item.Properties()));
public static final Item GINGERBREAD_SHINGLE_SLAB = registerItem("gingerbread_shingle_slab", new BlockItem(SGBlocks.GINGERBREAD_SHINGLE_SLAB, new Item.Properties()));

// Gingerbread door
public static final Item GINGERBREAD_DOOR = registerItem("gingerbread_door", new DoubleHighBlockItem(SGBlocks.GINGERBREAD_DOOR, new Item.Properties()));

// endregion

public static final Item PEPPERMINT_BLOCK = registerItem("peppermint_block", new BlockItem(SGBlocks.PEPPERMINT_BLOCK, new Item.Properties()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,28 @@
"rotation": ["Math.cos((query.anim_time - 0.0) * 720) * -45", 0, 0]
}
}
},
"animation.gingerbread_man.sit": {
"loop": true,
"bones": {
"root": {
"position": [0, -3.5, 0]
},
"left_arm": {
"rotation": [0, "((math.cos(query.life_time * 90) * 2.865) + 2.865) *-1.0", 45],
"position": [0.25, 1, 0.25]
},
"right_arm": {
"rotation": [0, "((math.cos(query.life_time * 90) * 2.865) + 2.865) *-1.0", -45],
"position": [-0.25, 1, 0.25]
},
"left_leg": {
"rotation": [-90, -22.5, 0]
},
"right_leg": {
"rotation": [-90, 22.5, 0]
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"variants": {
"facing=east,half=lower,hinge=left,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_left"
},
"facing=east,half=lower,hinge=left,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_left_open",
"y": 90
},
"facing=east,half=lower,hinge=right,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_right"
},
"facing=east,half=lower,hinge=right,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_right_open",
"y": 270
},
"facing=east,half=upper,hinge=left,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_top_left"
},
"facing=east,half=upper,hinge=left,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_top_left_open",
"y": 90
},
"facing=east,half=upper,hinge=right,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_top_right"
},
"facing=east,half=upper,hinge=right,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_top_right_open",
"y": 270
},
"facing=north,half=lower,hinge=left,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_left",
"y": 270
},
"facing=north,half=lower,hinge=left,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_left_open"
},
"facing=north,half=lower,hinge=right,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_right",
"y": 270
},
"facing=north,half=lower,hinge=right,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_right_open",
"y": 180
},
"facing=north,half=upper,hinge=left,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_top_left",
"y": 270
},
"facing=north,half=upper,hinge=left,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_top_left_open"
},
"facing=north,half=upper,hinge=right,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_top_right",
"y": 270
},
"facing=north,half=upper,hinge=right,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_top_right_open",
"y": 180
},
"facing=south,half=lower,hinge=left,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_left",
"y": 90
},
"facing=south,half=lower,hinge=left,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_left_open",
"y": 180
},
"facing=south,half=lower,hinge=right,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_right",
"y": 90
},
"facing=south,half=lower,hinge=right,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_right_open"
},
"facing=south,half=upper,hinge=left,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_top_left",
"y": 90
},
"facing=south,half=upper,hinge=left,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_top_left_open",
"y": 180
},
"facing=south,half=upper,hinge=right,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_top_right",
"y": 90
},
"facing=south,half=upper,hinge=right,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_top_right_open"
},
"facing=west,half=lower,hinge=left,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_left",
"y": 180
},
"facing=west,half=lower,hinge=left,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_left_open",
"y": 270
},
"facing=west,half=lower,hinge=right,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_right",
"y": 180
},
"facing=west,half=lower,hinge=right,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_bottom_right_open",
"y": 90
},
"facing=west,half=upper,hinge=left,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_top_left",
"y": 180
},
"facing=west,half=upper,hinge=left,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_top_left_open",
"y": 270
},
"facing=west,half=upper,hinge=right,open=false": {
"model": "seasonsgreetings:block/gingerbread_door_top_right",
"y": 180
},
"facing=west,half=upper,hinge=right,open=true": {
"model": "seasonsgreetings:block/gingerbread_door_top_right_open",
"y": 90
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/door_bottom_left",
"textures": {
"bottom": "seasonsgreetings:block/gingerbread_door_bottom",
"top": "seasonsgreetings:block/gingerbread_door_top"
}
}
Loading

0 comments on commit b10f057

Please sign in to comment.