Skip to content

Commit

Permalink
1.20.1 Update - 90% Conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
weirtz committed Aug 5, 2023
1 parent c802a6e commit ffd465e
Show file tree
Hide file tree
Showing 38 changed files with 3,347 additions and 144 deletions.
888 changes: 888 additions & 0 deletions hs_err_pid5048.log

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/main/java/com/seabreyh/mana/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.seabreyh.mana;

import net.minecraftforge.api.distmarker.OnlyIn;

import com.seabreyh.mana.client.renderers.item.ManaItemRenderProperties;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.common.Mod;

@OnlyIn(Dist.CLIENT)
@Mod.EventBusSubscriber(modid = ManaMod.MOD_ID, value = Dist.CLIENT)
public class ClientProxy extends CommonProxy {
public void init() {
}

public void clientInit() {
}

@Override
public Object getISTERProperties() {
return new ManaItemRenderProperties();
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/seabreyh/mana/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.seabreyh.mana;

import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ManaMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class CommonProxy {
public void init() {
}

public void clientInit() {
}

public Object getISTERProperties() {
return null;
}
}
14 changes: 8 additions & 6 deletions src/main/java/com/seabreyh/mana/ManaMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// import com.seabreyh.mana.registry.ManaCreativeTab;
// import com.seabreyh.mana.registry.ManaEntities;
import com.seabreyh.mana.registry.ManaItems;
// import com.seabreyh.mana.registry.ManaParticles;
// import com.seabreyh.mana.registry.ManaPotions;
// import com.seabreyh.mana.registry.ManaRecipes;
// import com.seabreyh.mana.registry.ManaSounds;
Expand All @@ -26,6 +25,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FlowerPotBlock;
import net.minecraftforge.client.event.RegisterParticleProvidersEvent;
import net.minecraftforge.common.MinecraftForge;
//import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.registries.RegisterEvent;
Expand All @@ -44,8 +44,9 @@
@Mod(ManaMod.MOD_ID)
public class ManaMod {
public static final String MOD_ID = "mana";
// public static CommonProxy PROXY = DistExecutor.runForDist(() ->
// ClientProxy::new, () -> CommonProxy::new);

public static CommonProxy PROXY = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new);

public static final Logger LOGGER = LogUtils.getLogger();

public ManaMod() {
Expand All @@ -71,7 +72,7 @@ public ManaMod() {
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);

// PROXY.init();
PROXY.init();
}

private void setup(final FMLCommonSetupEvent event) {
Expand Down Expand Up @@ -102,9 +103,10 @@ private void clientSetup(final FMLClientSetupEvent event) {
ManaClientEvents.registerBlockRenderers(event);
ManaClientEvents.registerBlockEntityRenderers(event);
ManaClientEvents.registerOverlays(event);
ManaClientEvents.registerMenuScreens(/* no event pls */);
ManaClientEvents.registerMenuScreens();
ManaClientEvents.registerParticleFactories(null);

// PROXY.clientInit();
PROXY.clientInit();
}

// You can use SubscribeEvent and let the Event Bus discover methods to call
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/seabreyh/mana/blocks/StarBottle.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
Expand All @@ -77,13 +78,15 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.SoundType;
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 net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
Expand All @@ -107,6 +110,14 @@ public class StarBottle extends Block implements SimpleWaterloggedBlock {
Block.box(5.5, 9, 5.5, 10.5, 10, 10.5),
Block.box(6.5, 8, 6.5, 9.5, 9, 9.5)).reduce((v1, v2) -> Shapes.join(v1, v2, BooleanOp.OR)).get();

public StarBottle() {
this(Properties.of()
.sound(SoundType.GLASS)
.strength(0.2f)
.destroyTime(0.3f)
.lightLevel(BlockState -> 15));
}

public StarBottle(BlockBehaviour.Properties p_153465_) {
super(p_153465_);
this.registerDefaultState(this.stateDefinition.any().setValue(HANGING, Boolean.valueOf(false))
Expand Down
190 changes: 190 additions & 0 deletions src/main/java/com/seabreyh/mana/blocks/StarCatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package com.seabreyh.mana.blocks;

import com.seabreyh.mana.blocks.entity.StarCatcherEntityBlock;
import com.seabreyh.mana.registry.ManaBlockEntities;

import java.util.stream.Stream;

import javax.annotation.Nullable;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
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.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.network.NetworkHooks;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;

public class StarCatcher extends BaseEntityBlock implements SimpleWaterloggedBlock {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final IntegerProperty FLOWING_WATER = IntegerProperty.create("water_level", 1, 8);

public StarCatcher() {
this(Properties.of()
.strength(0.2f)
.destroyTime(0.3f)
.lightLevel(BlockState -> 15));
}

public StarCatcher(Properties properties) {
super(properties);
this.registerDefaultState(this.getStateDefinition().any().setValue(WATERLOGGED, false));
}

private static final VoxelShape SHAPE = Stream.of(
Block.box(2, 1, 2, 14, 2, 14),
Block.box(4, 1.3, 4, 12, 2.3, 12),
Block.box(4, 1.3, 4, 12, 13.3, 12),
Block.box(2, 13, 2, 14, 14, 14),
Block.box(3, 0, 3, 13, 1, 13),
Block.box(3, 14, 3, 13, 15, 13),
Block.box(5, 15, 5, 11, 16, 11),
Block.box(3, 2, 3, 5, 13, 5),
Block.box(11, 2, 3, 13, 13, 5),
Block.box(11, 2, 11, 13, 13, 13),
Block.box(3, 2, 11, 5, 13, 13),
Block.box(5, 2, 12, 11, 3, 13),
Block.box(5, 2, 3, 11, 3, 4),
Block.box(3, 2, 5, 4, 3, 11),
Block.box(12, 2, 5, 13, 3, 11),
Block.box(5, 12, 12, 11, 13, 13),
Block.box(5, 12, 3, 11, 13, 4),
Block.box(3, 12, 5, 4, 13, 11),
Block.box(12, 12, 5, 13, 13, 11),
Block.box(7.5, 2.5, 7.5, 8.5, 3.8, 8.5),
Block.box(4, 12.7, 4, 12, 13.7, 12),
Block.box(7.5, 11.2, 7.5, 8.5, 12.5, 8.5)).reduce((v1, v2) -> Shapes.join(v1, v2, BooleanOp.OR)).get();

@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
return SHAPE;
}

// Waterlogging
public BlockState updateShape(BlockState thisState, Direction directionToNeighbor, BlockState neighborState,
LevelAccessor levelAccessor, BlockPos thisPos, BlockPos neighborPos) {
if (thisState.getValue(WATERLOGGED)) {
levelAccessor.scheduleTick(thisPos, Fluids.WATER, Fluids.WATER.getTickDelay(levelAccessor));
}

if (directionToNeighbor == Direction.DOWN && !thisState.canSurvive(levelAccessor, thisPos)) {
return Blocks.AIR.defaultBlockState();
} else {
return thisState;
}
}

public FluidState getFluidState(BlockState blockState) {
if (blockState.getValue(WATERLOGGED) && blockState.getValue(FLOWING_WATER) == 8) {
return Fluids.WATER.getSource(false);
} else if (blockState.getValue(WATERLOGGED) && blockState.getValue(FLOWING_WATER) != 8) {
return Fluids.WATER.getFlowing(blockState.getValue(FLOWING_WATER), false);
}
return Fluids.EMPTY.defaultFluidState();
}

// Facing
@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
FluidState fluidstate = pContext.getLevel().getFluidState(pContext.getClickedPos());
boolean flag = fluidstate.getType() == Fluids.WATER || fluidstate.getType() == Fluids.FLOWING_WATER;
boolean is_flowing = fluidstate.getType() == Fluids.FLOWING_WATER;
return this.defaultBlockState().setValue(WATERLOGGED, flag)
.setValue(FLOWING_WATER, is_flowing ? fluidstate.getAmount() : 8)
.setValue(FACING, pContext.getHorizontalDirection().getOpposite());
}

@Override
public BlockState rotate(BlockState pState, Rotation pRotation) {
return pState.setValue(FACING, pRotation.rotate(pState.getValue(FACING)));
}

@SuppressWarnings("deprecation")
@Override
public BlockState mirror(BlockState pState, Mirror pMirror) {
return pState.rotate(pMirror.getRotation(pState.getValue(FACING)));
}

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

// Block entity
@Override
public RenderShape getRenderShape(BlockState pState) {
return RenderShape.MODEL;
}

@SuppressWarnings("deprecation")
@Override
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
if (pState.getBlock() != pNewState.getBlock()) {
BlockEntity blockEntity = pLevel.getBlockEntity(pPos);
if (blockEntity instanceof StarCatcherEntityBlock) {
((StarCatcherEntityBlock) blockEntity).drops();
}
}
super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving);
}

@Override
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos,
Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
if (!pLevel.isClientSide()) {
BlockEntity entity = pLevel.getBlockEntity(pPos);
if (entity instanceof StarCatcherEntityBlock) {
NetworkHooks.openScreen(((ServerPlayer) pPlayer), (StarCatcherEntityBlock) entity, pPos);
} else {
throw new IllegalStateException("Our Container provider is missing!");
}
}
return InteractionResult.sidedSuccess(pLevel.isClientSide());
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
return new StarCatcherEntityBlock(pPos, pState);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState,
BlockEntityType<T> pBlockEntityType) {
return createTickerHelper(pBlockEntityType, ManaBlockEntities.STAR_CATCHER_ENTITY_BLOCK.get(),
StarCatcherEntityBlock::tick);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;

import net.minecraft.util.Mth;
import net.minecraft.world.Containers;
import net.minecraft.world.MenuProvider;
Expand All @@ -31,8 +31,9 @@
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;

import net.minecraftforge.items.IItemHandler;

public class StarCatcherEntityBlock extends BlockEntity implements MenuProvider {
Expand All @@ -57,7 +58,7 @@ public StarCatcherEntityBlock(BlockPos pWorldPosition, BlockState pBlockState) {

@Override
public Component getDisplayName() {
return new TextComponent("Star Catcher");
return Component.translatable("Star Catcher");
}

public float getRotationSpeed() {
Expand All @@ -77,7 +78,8 @@ public AbstractContainerMenu createMenu(int pContainerId, Inventory pInventory,
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @javax.annotation.Nullable Direction side) {
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
// https://docs.minecraftforge.net/en/1.20.x/datastorage/capabilities/
if (cap == ForgeCapabilities.ITEM_HANDLER) {
return lazyItemHandler.cast();
}

Expand Down
Loading

0 comments on commit ffd465e

Please sign in to comment.