Skip to content

Commit 969970c

Browse files
committed
Add #33 and part of #39
Added damage indicators as requested in Issue #33 . Added healing of golems by giving them their building blocks, as seen in #39. Added config value to disable this.
1 parent 808fbef commit 969970c

File tree

13 files changed

+160
-68
lines changed

13 files changed

+160
-68
lines changed

src/main/java/com/mcmoddev/golems/blocks/BlockUtility.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ protected boolean remove(final World worldIn, final BlockState state, final Bloc
5252
}
5353

5454
@Override
55-
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
55+
protected void fillStateContainer(final StateContainer.Builder<Block, BlockState> builder) {
5656
builder.add(BlockStateProperties.WATERLOGGED);
5757
}
5858

5959
@Override
60-
public Fluid pickupFluid(IWorld worldIn, BlockPos pos, BlockState state) {
60+
public Fluid pickupFluid(final IWorld worldIn, final BlockPos pos, final BlockState state) {
6161
if (state.get(BlockStateProperties.WATERLOGGED)) {
6262
worldIn.setBlockState(pos, state.with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(false)), 3);
6363
return Fluids.WATER;
@@ -67,18 +67,20 @@ public Fluid pickupFluid(IWorld worldIn, BlockPos pos, BlockState state) {
6767
}
6868

6969
@Override
70-
public IFluidState getFluidState(BlockState state) {
70+
public IFluidState getFluidState(final BlockState state) {
7171
return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false)
7272
: super.getFluidState(state);
7373
}
7474

7575
@Override
76-
public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, BlockState state, Fluid fluidIn) {
76+
public boolean canContainFluid(final IBlockReader worldIn, final BlockPos pos, final BlockState state,
77+
final Fluid fluidIn) {
7778
return !state.get(BlockStateProperties.WATERLOGGED) && fluidIn == Fluids.WATER;
7879
}
7980

8081
@Override
81-
public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFluidState fluidStateIn) {
82+
public boolean receiveFluid(final IWorld worldIn, final BlockPos pos, final BlockState state,
83+
final IFluidState fluidStateIn) {
8284
if (!state.get(BlockStateProperties.WATERLOGGED) && fluidStateIn.getFluid() == Fluids.WATER) {
8385
if (!worldIn.isRemote()) {
8486
worldIn.setBlockState(pos, state.with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(true)), 3);
@@ -92,7 +94,7 @@ public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFlu
9294
}
9395

9496
@Override
95-
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
97+
public void onBlockAdded(final BlockState state, final World worldIn, final BlockPos pos, final BlockState oldState, final boolean isMoving) {
9698
if(this.ticksRandomly(state)) {
9799
worldIn.getPendingBlockTicks().scheduleTick(pos, this, this.tickRate(worldIn));
98100
worldIn.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
@@ -106,7 +108,7 @@ public void randomTick(final BlockState state, final World worldIn, final BlockP
106108
}
107109

108110
@Override
109-
public int tickRate(IWorldReader worldIn) {
111+
public int tickRate(final IWorldReader worldIn) {
110112
return this.ticksRandomly ? tickRate : super.tickRate(worldIn);
111113
}
112114

@@ -151,19 +153,19 @@ public ItemStack getItem(final IBlockReader worldIn, final BlockPos pos, final B
151153
// }
152154

153155
@Override
154-
public boolean isReplaceable(BlockState state, BlockItemUseContext useContext) {
156+
public boolean isReplaceable(final BlockState state, final BlockItemUseContext useContext) {
155157
return true;
156158
}
157159

158160
@Nullable
159161
@Override
160-
public BlockState getStateForPlacement(BlockItemUseContext context) {
162+
public BlockState getStateForPlacement(final BlockItemUseContext context) {
161163
return getDefaultState();
162164
}
163165

164166
@Override
165-
public BlockState getStateForPlacement(BlockState state, Direction facing, BlockState state2, IWorld world,
166-
BlockPos pos1, BlockPos pos2, Hand hand) {
167+
public BlockState getStateForPlacement(final BlockState state, final Direction facing, final BlockState state2,
168+
final IWorld world, final BlockPos pos1, final BlockPos pos2, final Hand hand) {
167169
return getDefaultState();
168170
}
169171

@@ -172,7 +174,7 @@ public BlockState getStateForPlacement(BlockState state, Direction facing, Block
172174
*/
173175
@Deprecated
174176
@Override
175-
public BlockRenderType getRenderType(BlockState state) {
177+
public BlockRenderType getRenderType(final BlockState state) {
176178
return BlockRenderType.INVISIBLE;
177179
}
178180

@@ -193,7 +195,7 @@ public void onEntityCollision(final BlockState state, final World worldIn, final
193195
}
194196

195197
@Override
196-
public void onLanded(IBlockReader worldIn, Entity entityIn) {
198+
public void onLanded(final IBlockReader worldIn, final Entity entityIn) {
197199
// do nothing
198200
}
199201

src/main/java/com/mcmoddev/golems/blocks/BlockUtilityGlow.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public class BlockUtilityGlow extends BlockUtility {
1919
/* Default value for TICK_RATE. Not necessary to define through config. */
2020
public static final int UPDATE_TICKS = 6;
2121

22-
public BlockUtilityGlow(Material m, final float defaultLight, final int tickRate) {
22+
public BlockUtilityGlow(final Material m, final float defaultLight, final int tickRate) {
2323
super(Properties.create(m).tickRandomly().lightValue((int) (defaultLight * 15.0F)), tickRate);
2424
int light = (int) (defaultLight * 15.0F);
2525
this.setDefaultState(this.getDefaultState().with(LIGHT_LEVEL, light));
2626
}
2727

2828
@Override
29-
public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
29+
public void tick(final BlockState state, final World worldIn, final BlockPos pos, final Random random) {
3030
// make a slightly expanded AABB to check for the golem
3131
final AxisAlignedBB toCheck = new AxisAlignedBB(pos).grow(0.5D);
3232
// we'll probably only ever get one golem, but it doesn't hurt to be safe and check them all
@@ -42,13 +42,13 @@ public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
4242
}
4343

4444
@Override
45-
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
45+
protected void fillStateContainer(final StateContainer.Builder<Block, BlockState> builder) {
4646
super.fillStateContainer(builder);
4747
builder.add(LIGHT_LEVEL);
4848
}
4949

5050
@Override
51-
public int getLightValue(BlockState state) {
51+
public int getLightValue(final BlockState state) {
5252
return state.get(LIGHT_LEVEL);
5353
}
5454

src/main/java/com/mcmoddev/golems/blocks/BlockUtilityPower.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public BlockUtilityPower(final int powerLevel, final int tickRate) {
2626
}
2727

2828
@Override
29-
public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
29+
public void tick(final BlockState state, final World worldIn, final BlockPos pos, final Random random) {
3030
// make a slightly expanded AABB to check for the golem
3131
AxisAlignedBB toCheck = new AxisAlignedBB(pos).grow(0.25D);
3232
List<GolemBase> list = worldIn.getEntitiesWithinAABB(GolemBase.class, toCheck);
@@ -41,7 +41,7 @@ public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
4141
}
4242

4343
@Override
44-
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
44+
protected void fillStateContainer(final StateContainer.Builder<Block, BlockState> builder) {
4545
super.fillStateContainer(builder);
4646
builder.add(POWER_LEVEL);
4747
}
@@ -50,12 +50,12 @@ protected void fillStateContainer(StateContainer.Builder<Block, BlockState> buil
5050
* "Implementing/overriding is fine."
5151
*/
5252
@Override
53-
public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
53+
public int getWeakPower(final BlockState blockState, final IBlockReader blockAccess, final BlockPos pos, final Direction side) {
5454
return blockState.get(POWER_LEVEL);
5555
}
5656

5757
@Override
58-
public int getStrongPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
58+
public int getStrongPower(final BlockState blockState, final IBlockReader blockAccess, final BlockPos pos, final Direction side) {
5959
return blockState.get(POWER_LEVEL);
6060
}
6161

src/main/java/com/mcmoddev/golems/entity/BedrockGolem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public BedrockGolem(final EntityType<? extends GolemBase> entityType, final Worl
2323
}
2424

2525
@Override
26-
public boolean isInvulnerableTo(DamageSource source) {
26+
public boolean isInvulnerableTo(final DamageSource source) {
2727
return true;
2828
}
2929

src/main/java/com/mcmoddev/golems/entity/base/GolemBase.java

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.mcmoddev.golems.entity.ai.GoToWaterGoal;
55
import com.mcmoddev.golems.entity.ai.SwimUpGoal;
66
import com.mcmoddev.golems.entity.ai.SwimmingMovementController;
7+
import com.mcmoddev.golems.items.ItemBedrockGolem;
78
import com.mcmoddev.golems.main.ExtraGolemsEntities;
89
import com.mcmoddev.golems.util.config.ExtraGolemsConfig;
910
import com.mcmoddev.golems.util.config.GolemContainer;
@@ -19,19 +20,22 @@
1920
import net.minecraft.entity.MoverType;
2021
import net.minecraft.entity.SharedMonsterAttributes;
2122
import net.minecraft.entity.ai.goal.SwimGoal;
22-
import net.minecraft.entity.passive.IFlyingAnimal;
2323
import net.minecraft.entity.passive.IronGolemEntity;
24+
import net.minecraft.entity.player.PlayerEntity;
25+
import net.minecraft.item.BlockItem;
2426
import net.minecraft.item.ItemStack;
2527
import net.minecraft.nbt.CompoundNBT;
2628
import net.minecraft.network.datasync.DataParameter;
2729
import net.minecraft.network.datasync.DataSerializers;
2830
import net.minecraft.network.datasync.EntityDataManager;
31+
import net.minecraft.particles.ParticleTypes;
2932
import net.minecraft.pathfinding.GroundPathNavigator;
3033
import net.minecraft.pathfinding.PathNodeType;
3134
import net.minecraft.pathfinding.SwimmerPathNavigator;
3235
import net.minecraft.potion.EffectInstance;
3336
import net.minecraft.potion.Effects;
3437
import net.minecraft.util.DamageSource;
38+
import net.minecraft.util.Hand;
3539
import net.minecraft.util.ResourceLocation;
3640
import net.minecraft.util.SoundEvent;
3741
import net.minecraft.util.SoundEvents;
@@ -112,6 +116,8 @@ protected void registerData() {
112116
super.registerData();
113117
this.getDataManager().register(CHILD, Boolean.valueOf(false));
114118
}
119+
120+
/////////////// GOLEM UTILITY METHODS //////////////////
115121

116122
/**
117123
* Whether right-clicking on this entity triggers a texture change.
@@ -147,11 +153,39 @@ public boolean isProvidingPower() {
147153
return false;
148154
}
149155

156+
/** @return the Golem Container **/
150157
public GolemContainer getGolemContainer() {
151158
return container != null ? container : GolemRegistrar.getContainer(this.getType().getRegistryName());
152159
}
160+
161+
/**
162+
* @param i the ItemStack being applied to the golem
163+
* @return true if the golem can be built the given item-block
164+
**/
165+
public boolean isHealingItem(final ItemStack i) {
166+
if(!i.isEmpty() && i.getItem() instanceof BlockItem) {
167+
for(final Block b : getGolemContainer().getBuildingBlocks()) {
168+
if(i.isItemEqual(new ItemStack(b))) {
169+
return true;
170+
}
171+
}
172+
}
173+
return false;
174+
}
175+
176+
/**
177+
* @param i the ItemStack being used to heal the golem
178+
* @return the amount by which this item should heal the golem,
179+
* in half-hearts. Defaults to 25% of max health or 32.0,
180+
* whichever is smaller
181+
**/
182+
public float getHealAmount(final ItemStack i) {
183+
return Math.min(this.getMaxHealth() * 0.25F, 32.0F);
184+
}
185+
186+
/////////////// CONFIG HELPERS //////////////////
153187

154-
public ForgeConfigSpec.ConfigValue getConfigValue(String name) {
188+
public ForgeConfigSpec.ConfigValue getConfigValue(final String name) {
155189
return (ExtraGolemsConfig.GOLEM_CONFIG.specials.get(this.getGolemContainer().specialContainers.get(name))).value;
156190
}
157191

@@ -166,6 +200,8 @@ public int getConfigInt(final String name) {
166200
public double getConfigDouble(final String name) {
167201
return (Double) getConfigValue(name).get();
168202
}
203+
204+
/////////////// OVERRIDEN BEHAVIOR //////////////////
169205

170206
@Override
171207
public void fall(float distance, float damageMultiplier) {
@@ -183,9 +219,10 @@ public void fall(float distance, float damageMultiplier) {
183219
int j = MathHelper.floor(this.posX);
184220
int k = MathHelper.floor(this.posY - (double)0.2F);
185221
int l = MathHelper.floor(this.posZ);
186-
BlockState blockstate = this.world.getBlockState(new BlockPos(j, k, l));
187-
if (!blockstate.isAir()) {
188-
SoundType soundtype = blockstate.getSoundType(world, new BlockPos(j, k, l), this);
222+
final BlockPos pos = new BlockPos(j, k, l);
223+
BlockState blockstate = this.world.getBlockState(pos);
224+
if (!this.world.isAirBlock(pos)) {
225+
SoundType soundtype = blockstate.getSoundType(world, pos, this);
189226
this.playSound(soundtype.getFallSound(), soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
190227
}
191228
}
@@ -228,6 +265,29 @@ public ItemStack getPickedResult(final RayTraceResult ray) {
228265
return block != null ? new ItemStack(block) : ItemStack.EMPTY;
229266
}
230267

268+
@Override
269+
protected boolean processInteract(final PlayerEntity player, final Hand hand) {
270+
final ItemStack stack = player.getHeldItem(hand);
271+
if(ExtraGolemsConfig.enableHealGolems() && this.getHealth() < this.getMaxHealth() && isHealingItem(stack)) {
272+
heal(getHealAmount(stack));
273+
stack.shrink(1);
274+
// if currently attacking this player, stop
275+
if(this.getAttackTarget() == player) {
276+
this.setRevengeTarget(null);
277+
this.setAttackTarget(null);
278+
}
279+
// spawn particles and play sound
280+
if(this.world.isRemote) {
281+
ItemBedrockGolem.spawnParticles(this.world, this.posX - 0.5D, this.posY + this.getHeight() / 2.0D,
282+
this.posZ - 0.5D, 0.12D, ParticleTypes.HAPPY_VILLAGER, 20);
283+
}
284+
this.playSound(SoundEvents.BLOCK_STONE_PLACE, 0.85F, 1.1F + rand.nextFloat() * 0.2F);
285+
return true;
286+
} else {
287+
return super.processInteract(player, hand);
288+
}
289+
}
290+
231291
@Override
232292
public boolean isChild() {
233293
return this.getDataManager().get(CHILD).booleanValue();

src/main/java/com/mcmoddev/golems/renders/ModelGolem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import net.minecraftforge.api.distmarker.OnlyIn;
99

1010
@OnlyIn(Dist.CLIENT)
11-
public class ModelGolem extends EntityModel<GolemBase> {
11+
public class ModelGolem<T extends GolemBase> extends EntityModel<T> {
1212

1313
/**
1414
* The head model for the iron golem.
@@ -73,7 +73,7 @@ public ModelGolem(final float f1, final float f2) {
7373
* Sets the models various rotation angles then renders the model.
7474
*/
7575
@Override
76-
public void render(final GolemBase entityIn, final float limbSwing, final float limbSwingAmount, final float ageInTicks,
76+
public void render(final T entityIn, final float limbSwing, final float limbSwingAmount, final float ageInTicks,
7777
final float netHeadYaw, final float headPitch, final float scale) {
7878

7979
this.setRotationAngles(entityIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
@@ -102,7 +102,7 @@ public void render(final GolemBase entityIn, final float limbSwing, final float
102102
* back and forth) and par2 represents how "far" arms and legs can swing at most.
103103
*/
104104
@Override
105-
public void setRotationAngles(final GolemBase entity, final float limbSwing, final float limbSwingAmount, final float ageInTicks,
105+
public void setRotationAngles(final T entity, final float limbSwing, final float limbSwingAmount, final float ageInTicks,
106106
final float netHeadYaw, final float headPitch, final float scaleFactor) {
107107
this.golemHead.rotateAngleY = netHeadYaw / (180F / (float) Math.PI);
108108
this.golemHead.rotateAngleX = headPitch / (180F / (float) Math.PI);
@@ -119,7 +119,7 @@ public void setRotationAngles(final GolemBase entity, final float limbSwing, fin
119119
* are the same second and third as in the setRotationAngles method.
120120
*/
121121
@Override
122-
public void setLivingAnimations(final GolemBase entity, final float limbSwing,
122+
public void setLivingAnimations(final T entity, final float limbSwing,
123123
final float limbSwingAmount, final float partialTickTime) {
124124
int i = entity.getAttackTimer();
125125

0 commit comments

Comments
 (0)