Skip to content

Commit

Permalink
Fixed when not being able strip logs with some modded axes
Browse files Browse the repository at this point in the history
  • Loading branch information
LopyLuna committed Sep 19, 2024
1 parent 0396ed8 commit d071e3e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 57 deletions.
2 changes: 2 additions & 0 deletions src/main/java/uwu/lopyluna/create_dd/DesiresCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public DesiresCreate() {

public static void init(final FMLCommonSetupEvent event) {
DesiresFluids.registerFluidInteractions();

event.enqueueWork(() -> DesiresWoodType.regStrippables());
}

public static ResourceLocation asResource(String path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
package uwu.lopyluna.create_dd.content.blocks.functional;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraftforge.common.ToolAction;
import net.minecraftforge.common.ToolActions;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Objects;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class AxisBlock extends RotatedPillarBlock {
boolean hasStrippedWood;
BlockState strippedWood;
boolean isFlammable;
int getFlammability;
int getFireSpreadSpeed;

public static AxisBlock create(Properties properties) {
return new AxisBlock(properties, false, Blocks.AIR.defaultBlockState(), false, 0, 0);
return new AxisBlock(properties, false, 0, 0);
}
public static AxisBlock create(Properties properties, int getFlammability, int getFireSpreadSpeed) {
return new AxisBlock(properties, false, Blocks.AIR.defaultBlockState(), true, getFlammability, getFireSpreadSpeed);
}
public static AxisBlock create(Properties properties, BlockState strippedWood) {
return new AxisBlock(properties, true, strippedWood, false, 0, 0);
}
public static AxisBlock create(Properties properties, BlockState strippedWood, int getFlammability, int getFireSpreadSpeed) {
return new AxisBlock(properties, true, strippedWood, true, getFlammability, getFireSpreadSpeed);
return new AxisBlock(properties, true, getFlammability, getFireSpreadSpeed);
}

public AxisBlock(Properties properties, boolean hasStrippedWood, BlockState strippedWood, boolean isFlammable, int getFlammability, int getFireSpreadSpeed) {
public AxisBlock(Properties properties, boolean isFlammable, int getFlammability, int getFireSpreadSpeed) {
super(properties);
this.hasStrippedWood = hasStrippedWood;
this.strippedWood = strippedWood;
this.isFlammable = isFlammable;
this.getFlammability = getFlammability;
this.getFireSpreadSpeed = getFireSpreadSpeed;
Expand All @@ -70,29 +44,4 @@ public int getFlammability(BlockState state, BlockGetter world, BlockPos pos, Di
public int getFireSpreadSpeed(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
return getFireSpreadSpeed;
}

@Override
public @Nullable BlockState getToolModifiedState(BlockState state, UseOnContext context, ToolAction toolAction, boolean simulate) {
if (hasStrippedWood && ToolActions.AXE_STRIP == toolAction && state.is(this)) {
Level level = context.getLevel();
Player player = context.getPlayer();
BlockPos blockPos = context.getClickedPos();
InteractionHand interactionHand = Objects.requireNonNull(context.getPlayer()).getUsedItemHand();
ItemStack item = Objects.requireNonNull(player).getItemInHand(interactionHand);
BlockState newState = strippedWood.setValue(AXIS, state.getValue(AXIS));

if (item.getItem() instanceof AxeItem) {
if (player instanceof ServerPlayer) {
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer)player, blockPos, item);
}

//level.setBlock(blockPos, newState, 11);
level.gameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Context.of(player, newState));
item.hurtAndBreak(1, player, playerEntity -> playerEntity.broadcastBreakEvent(interactionHand));
level.playSound(player, blockPos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
return newState;
}
}
return super.getToolModifiedState(state, context, toolAction, simulate);
}
}
14 changes: 14 additions & 0 deletions src/main/java/uwu/lopyluna/create_dd/registry/DesiresWoodType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import static uwu.lopyluna.create_dd.DesiresCreate.REGISTRATE;
import static uwu.lopyluna.create_dd.registry.helper.woodtype.WoodEntry.*;

import com.google.common.collect.Maps;
import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorRenderer;
import com.tterrag.registrate.util.entry.BlockEntityEntry;
import net.minecraft.world.item.AxeItem;
import uwu.lopyluna.create_dd.content.blocks.functional.sliding_door.WoodenSlidingDoorBlockEntity;
import uwu.lopyluna.create_dd.registry.helper.woodtype.WoodEntry;
import uwu.lopyluna.create_dd.registry.helper.woodtype.WoodTypes;
Expand All @@ -25,5 +27,17 @@ public class DesiresWoodType {
.validBlocks(ROSE.slidingDoor, SMOKED.slidingDoor, SPIRIT.slidingDoor)
.register();

public static void regStrippables() {
regStrippables(ROSE);
regStrippables(SMOKED);
regStrippables(RUBBER);
regStrippables(SPIRIT);
}

public static void regStrippables(WoodEntry entry) {
AxeItem.STRIPPABLES = Maps.newHashMap(AxeItem.STRIPPABLES);
AxeItem.STRIPPABLES.put(entry.log.get(), entry.strippedLog.get());
}

public static void register() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public static WoodEntry create(String name, WoodTypes type, boolean flammable, b
BlockEntry<ConnectedGlassPaneBlock> window_pane;

if (anyAll) {

woodType = WoodType.create(id);
plank = REGISTRATE.block(id + "_planks", flammable ? p -> CombustibleBlock.create(p, 5, 20) : CombustibleBlock::create)
.initialProperties(() -> Blocks.OAK_PLANKS)
Expand Down Expand Up @@ -233,7 +234,7 @@ public static WoodEntry create(String name, WoodTypes type, boolean flammable, b
.tab(tab)
.build()
.register();
log = REGISTRATE.block(id + "_log", flammable ? p -> AxisBlock.create(p, strippedLog.get().defaultBlockState(), 5, 5) : p -> AxisBlock.create(p, strippedLog.get().defaultBlockState()))
log = REGISTRATE.block(id + "_log", flammable ? p -> AxisBlock.create(p, 5, 5) : AxisBlock::create)
.initialProperties(() -> Blocks.OAK_LOG)
.lang(name + " Log")
.blockstate((c, p) -> p.axisBlock(c.get(), DesiresCreate.asResource(texturePathID + "_log"), DesiresCreate.asResource(texturePathID + "_log_top")))
Expand Down Expand Up @@ -270,7 +271,7 @@ public static WoodEntry create(String name, WoodTypes type, boolean flammable, b
.tab(tab)
.build()
.register();
wood = REGISTRATE.block(id + "_wood", flammable ? p -> AxisBlock.create(p, strippedWood.get().defaultBlockState(), 5, 5) : p -> AxisBlock.create(p, strippedWood.get().defaultBlockState()))
wood = REGISTRATE.block(id + "_wood", flammable ? p -> AxisBlock.create(p, 5, 5) : AxisBlock::create)
.initialProperties(() -> Blocks.OAK_WOOD)
.lang(name + " Wood")
.blockstate((c, p) -> p.axisBlock(c.get(), DesiresCreate.asResource(texturePathID + "_log"), DesiresCreate.asResource(texturePathID + "_log")))
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
public net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity f_58318_
public net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity f_58319_
public net.minecraft.world.entity.Entity f_19796_ # random
public net.minecraft.world.entity.Entity f_19796_ # random
public-f net.minecraft.world.item.AxeItem f_150683_ # STRIPPABLES
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit d071e3e

Please sign in to comment.