add resources, imports and some leti among various finishings

This commit is contained in:
Ella Paws 2022-02-06 03:45:18 +01:00
parent bb8486a8eb
commit f9c6de9fec
49 changed files with 203 additions and 60 deletions

View File

@ -1,6 +1,11 @@
package ella.techia.block;
import ella.techia.registry.TechiaRegistry;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -33,4 +38,12 @@ public class BoxBlock extends ToolBlock implements BlockEntityProvider {
((BoxBlockEntity)blockEntity).setCustomName(itemStack.getName());
}
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
if(!world.isClient){
player.incrementStat(TechiaRegistry.INTERACT_WITH_BOX);
}
return super.onUse(state, world, pos, player, hand, hit);
}
}

View File

@ -38,7 +38,34 @@ public class Connector extends LetiConnectable /*implements LetiBlock, Waterlogg
}
@Override
public void onPlace(){
LetiNetwork.new(pos);
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity unrelatedEntity, ItemStack stack){
super.onPlaced(world, pos, state, unrelatedEntity, stack);
LetiNetwork.new(world, pos);
}
@Override
public void onBroken(World world, BlockPos pos, BlockState state){
super.onBroken(world, pos, state);
LetiNetwork.remove(world, pos);
}
@Override
public BlockState getStateForNeighborUpdate(
BlockState state,
Direction side,
BlockState neighborState,
WorldAccess world,
BlockPos pos,
BlockPos neighborPos
){
// can't be assed to only update one side
// FIXME probably extremely laggy on medium to big networks
return state
.with(Properties.NORTH, LetiNetwork.connects(world.getBlockState(pos.north()), Direction.SOUTH))
.with(Properties.SOUTH, LetiNetwork.connects(world.getBlockState(pos.south()), Direction.NORTH))
.with(Properties.EAST , LetiNetwork.connects(world.getBlockState(pos.east() ), Direction.WEST ))
.with(Properties.WEST , LetiNetwork.connects(world.getBlockState(pos.west() ), Direction.EAST ))
.with(Properties.UP , LetiNetwork.connects(world.getBlockState(pos.up() ), Direction.DOWN ))
.with(Properties.DOWN , LetiNetwork.connects(world.getBlockState(pos.down() ), Direction.UP ))
/*.with(Properties.POWERED, /*powered(world.getBlockState(pos))* /false)*/;
}
}

View File

@ -1,31 +1,21 @@
package ella.techia.block;
import ella.techia.block.entity.SmelterEntity;
import ella.techia.registry.TechiaRegistry;
import java.util.Random;
import net.minecraft.block.*;
//import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
//import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
public class Smelter extends BlockWithEntity implements BlockEntityProvider {
public class Smelter extends BlockWithEntity {
public EllasModLampBlock(net.minecraft.block.AbstractBlock.Settings settings){
public Smelter(net.minecraft.block.AbstractBlock.Settings settings){
super(settings);
}
@ -37,13 +27,12 @@ public class Smelter extends BlockWithEntity implements BlockEntityProvider {
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
if(!world.isClient){
//This will call the createScreenHandlerFactory method from BlockWithEntity, which will return our blockEntity casted to
//a namedScreenHandlerFactory.
NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos);
if(screenHandlerFactory != null){
//With this call the server will request the client to open the appropriate Screenhandler
player.openHandledScreen(screenHandlerFactory);
player.incrementStat(TechiaRegistry.INTERACT_WITH_SMELTER);
return ActionResult.CONSUME;
}
}
return ActionResult.SUCCESS;
@ -58,10 +47,15 @@ public class Smelter extends BlockWithEntity implements BlockEntityProvider {
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved){
if(state.getBlock() != newState.getBlock()){
BlockEntity blockEntity = world.getBlockEntity(pos);
if(blockEntity instanceof WorkbenchBlockEntity){
ItemScatterer.spawn(world, pos, (WorkbenchBlockEntity)blockEntity);
if(blockEntity instanceof SmelterEntity){
ItemScatterer.spawn(world, pos, (SmelterEntity)blockEntity);
}
super.onStateReplaced(state, world, pos, newState, moved);
}
}
/*@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random){
TODO particles and/or sound
}*/
}

View File

@ -1,14 +1,10 @@
package ella.techia.block;
import net.minecraft.block.*;
//import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
//import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
@ -16,18 +12,15 @@ import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
public class ToolBlock extends BlockWithEntity implements Waterloggable {
static final VoxelShape SHAPE = createCuboidShape( 2d, 0d, 2d, 14d, 12d, 14d);
public EllasModLampBlock(net.minecraft.block.AbstractBlock.Settings settings){
public ToolBlock(net.minecraft.block.AbstractBlock.Settings settings){
super(settings);
this.setDefaultState(
this.stateManager.getDefaultState()
@ -48,13 +41,11 @@ public class ToolBlock extends BlockWithEntity implements Waterloggable {
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
if(!world.isClient){
//This will call the createScreenHandlerFactory method from BlockWithEntity, which will return our blockEntity casted to
//a namedScreenHandlerFactory.
NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos);
if(screenHandlerFactory != null){
//With this call the server will request the client to open the appropriate Screenhandler
player.openHandledScreen(screenHandlerFactory);
return ActionResult.CONSUME;
}
}
return ActionResult.SUCCESS;
@ -70,10 +61,7 @@ public class ToolBlock extends BlockWithEntity implements Waterloggable {
return super.getPlacementState(context)
.with(Properties.WATERLOGGED, context.getWorld().getFluidState(context.getBlockPos()).getFluid() == Fluids.WATER);
}
/*@Override
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type){
return false;
}*/
@Override
public FluidState getFluidState(BlockState state){
if(state.get(Properties.WATERLOGGED)) return Fluids.WATER.getStill(false);

View File

@ -1,6 +1,11 @@
package ella.techia.block;
import ella.techia.registry.TechiaRegistry;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -24,4 +29,12 @@ public class WorkbenchBlock extends ToolBlock implements BlockEntityProvider {
super.onStateReplaced(state, world, pos, newState, moved);
}
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
if(!world.isClient){
player.incrementStat(TechiaRegistry.INTERACT_WITH_WORKBENCH);
}
return super.onUse(state, world, pos, player, hand, hit);
}
}

View File

@ -0,0 +1,47 @@
package ella.techia.block.entity;
import net.minecraft.nbt.*;
public class SmelterEntity extends BlockEntity implements ImplInventory {
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize(8, ItemStack.EMPTY);
//private ItemStack shape = ItemStack.EMPTY;
private int remainingSmeltTime = 0;
private int remainingFuelTime = 0;
public SmelterEntity(BlockPos pos, BlockState state){
super(ExampleMod.SMELTER_ENTITY, pos, state);
}
@Override
public DefaultedList<ItemStack> getItems(){
return inventory;
}
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player){
return new SmelterScreenHandler(syncId, playerInventory, this);
}
@Override
public Text getDisplayName(){
return new TranslatableText(getCachedState().getBlock().getTranslationKey());
}
@Override
public void readNbt(NbtCompound nbt){
super.readNbt(nbt);
Inventories.readNbt(nbt, inventory);
if(nbt.get("Fuel").getType() == NbtElement.INT_TYPE)
remainingFuelTime = nbt.getInt("Fuel");
if(nbt.get("SmeltTime").getType() == NbtElement.INT_TYPE)
remainingSmeltTime = nbt.getInt("SmeltTime");
}
@Override
public NbtCompound writeNbt(NbtCompound nbt){
Inventories.writeNbt(nbt, inventory);
nbt.putInt("Fuel", remainingFuelTime);
nbt.putInt("SmeltTime", remainingSmeltTime);
return super.writeNbt(nbt);
}
}

View File

@ -4,6 +4,7 @@ import java.util.*;
import java.util.Map.Entry;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.ServerWorld;
public class LetiNetwork {
@ -11,12 +12,19 @@ public class LetiNetwork {
private ServerWorld world;
ArrayList<BlockPos> nodes;
ArrayList<Entry<BlockPos, Direction>> inputs;
public LetiNetwork(ServerWorld world, BlockPos pos){
this.world = world;
nodes = new ArrayList<>();
nodes.add(pos);
inputs = new ArrayList<>();
// TODO population of inputs is nowhere in the code
// NOTE handling outputs probably happens when set(boolean) updates states, but we may want to look into this further
}
// NOTE that this code assumes correct behaviour of callers and that it does what it's meant to do
// this is of course not ideal, but as long as it's not messed up in this mod it should be fine...
public void set(boolean powered){
for(BlockPos pos : nodes){
world.setBlockState(pos, world.getBlockState(pos).with(Properties.POWERED, powered));
@ -44,19 +52,48 @@ public class LetiNetwork {
}
}
private void add(BlockPos pos){
public static LetiNetwork at(ServerWorld world, BlockPos pos){
return networks.get(new Entry<ServerWorld, BlockPos>(world, pos));
}
private void add(ServerWorld world, BlockPos pos){
nodes.add(pos);
networks.set(new Entry<ServerWorld, BlockPos>(world, pos), this);
}
private void remove(BlockPos pos){
private void remove(ServerWorld world, BlockPos pos){
nodes.remove(pos);
networks.remove(new Entry<ServerWorld, BlockPos>(world, pos));
// FIXME known bug: won't separate networks
// start at pos, traverse neighbours (and add those searched to an array to prevent loops),
// check if we found all (equal), report error if too many entries were found
// if fewer entries were found, traverse through all other directions and replace those to a new network
// i was thinking what if these blocks are on different networks but that should never happen
// this code is a start but recursion...
/*ArrayList<BlockPos> found;
int finds = 0;
for(BlockPos np : neighbors(pos)){
Entry<ServerWorld, BlockPos> key = new Entry<>(world, np);
if(networks.containsKey(key)){
LetiNetwork n = networks.get(key);
if(!found.contains(key.getValue())){
found.add(key.getValue());
++finds;
recurse(np);
}
}
}*/
}
private void addInput(ServerWorld world, BlockPos pos, Direction direction){
inputs.add(new Entry<BlockPos, Direction>(pos, direction));
}
private void removeInput(ServerWorld world, BlockPos pos, Direction direction){
inputs.remove(new Entry<BlockPos, Direction>(pos, direction));
}
private void mergeWith(LetiNetwork network){
for(BlockPos pos : nodes){
Entry<ServerWorld, BlockPos> entry = new Entry<>(world, pos)
//networks.remove(entry); (not needed because we replace)
network.add(pos);
networks.set(entry, network);
}
@ -105,4 +142,16 @@ public class LetiNetwork {
}
};
}
public static ArrayList<LetiNetwork> findAdjacentNetworks(){
ArrayList<LetiNetwork> ret;
for(BlockPos np : neighbors(pos)){
Entry<ServerWorld, BlockPos> key = new Entry<>(world, np);
if(networks.containsKey(key)){
LetiNetwork n = networks.get(key);
if(!ret.contains(n)) ret.add(n);
}
}
return n;
}
}

View File

@ -5,22 +5,18 @@ import ella.techia.block.*;
import ella.techia.block.entity.*;
//import net.fabricmc.api.FabricLoader;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.fabricmc.fabric.api.registry.FuelRegistry;
//import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
//import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.minecraft.block.*;
import net.minecraft.entity.EntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.SignItem;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.property.Properties;
//import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockView;
import java.util.LinkedHashMap;
import java.util.Map;
//import java.util.LinkedHashMap;
//import java.util.Map;
public class TechiaRegistry {
/*private static final LinkedHashMap<String, Block> BLOCKS = new LinkedHashMap<>();
@ -29,7 +25,12 @@ public class TechiaRegistry {
public static final Block ASMITE_BLOCK = add("asmite_block",
new Block(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK)), ItemGroup.BUILDING_BLOCKS);
public static final Item ASMITE_INGOT = addI("asmite_ingot", new Item(new Item.Settings().group(ItemGroup.MISC)));
public static final Item LETIUM = addI("letium", new Item(new Item.Settings().group(ItemGroup.MISC)));
public static final Item LETIUM = addI("letium", new Item(new Item.Settings().group(ItemGroup.MISC))/*{
@Override
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
tooltip.add(new TranslatableText("item." + Techia.MOD_ID + ".letium.desc"));
}
}*/);
public static final Block CONNECTOR = add("connector", new Connector(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), Techia.LETI);
//public static final Block INTERSECTOR = add("intersector", new Intersector(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), Techia.LETI); NOPE
public static final Block INVERTER = add("inverter", new Inverter(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), Techia.LETI);
@ -47,11 +48,15 @@ public class TechiaRegistry {
public static BlockEntityType<WorkbenchBlockEntity> WORKBENCH_BLOCK_ENTITY;
public static final Block PISTON = add("piston",
new Block(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK)), Techia.LETI);
new Piston(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK)), Techia.LETI);
public static final RecipeType<SmelterRecipe> WORKBENCH_RECIPE = RecipeType.register(new Identifier(Techia.MOD_ID, "smelting"));
public static final RecipeType<WorkbenchRecipe> WORKBENCH_RECIPE = RecipeType.register(new Identifier(Techia.MOD_ID, "workbench"));
public static final Identifier INTERACT_WITH_SMELTER = new Identifier(Techia.MOD_ID, "interact_with_smelter");
public static final Identifier INTERACT_WITH_BOX = new Identifier(Techia.MOD_ID, "interact_with_box");
public static final Identifier INTERACT_WITH_WORKBENCH = new Identifier(Techia.MOD_ID, "interact_with_workbench");
private static <B extends Block> B add(String name, B block, ItemGroup tab){
return add(name, block, new BlockItem(block, new Item.Settings().group(tab)));
}
@ -111,7 +116,7 @@ public class TechiaRegistry {
//register("asmite_wall_button", ASMITE_WALL_BUTTON);
//register("asmite_wall_toggle", ASMITE_WALL_TOGGLE);
register("smelter", SMELTER);
SMELTER_ENTITY = register("smelter", FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, BOX_BLOCK).build(null));
SMELTER_ENTITY = register("smelter", FabricBlockEntityTypeBuilder.create(SmelterEntity::new, SMELTER).build(null));
register("block_shape", BLOCK_SHAPE);
register("ingot_shape", INGOT_SHAPE);
register("box", BOX_BLOCK);
@ -119,6 +124,13 @@ public class TechiaRegistry {
register("workbench", WORKBENCH_BLOCK);
WORKBENCH_BLOCK_ENTITY = register("workbench", FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, WORKBENCH_BLOCK).build(null));
register("piston", PISTON);
Registry.register(Registry.CUSTOM_STAT, "interact_with_smelter", INTERACT_WITH_SMELTER);
Stats.CUSTOM.getOrCreateStat(INTERACT_WITH_SMELTER, StatFormatter.DEFAULT);
Registry.register(Registry.CUSTOM_STAT, "interact_with_box", INTERACT_WITH_BOX);
Stats.CUSTOM.getOrCreateStat(INTERACT_WITH_BOX, StatFormatter.DEFAULT);
Registry.register(Registry.CUSTOM_STAT, "interact_with_workbench", INTERACT_WITH_WORKBENCH);
Stats.CUSTOM.getOrCreateStat(INTERACT_WITH_WORKBENCH, StatFormatter.DEFAULT);
}
public void register(String id, Block block){
register(id), block);
@ -129,9 +141,4 @@ public class TechiaRegistry {
public BlockEntityType register(String id, BlockEntityType entity){
Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(Techia.MOD_ID, id), entity);
}
/*public static boolean never(BlockState state, BlockView world, BlockPos pos) {
return false;
}*/
}

View File

@ -18,4 +18,9 @@
"item.techia.letium":"Letium",
"item.techia.ingot_shape":"Ingot Shape",
"itemGroup.ellas_mod.items":"Techia",
"itemGroup.ellas_mod.leti":"Leti"}
"itemGroup.ellas_mod.leti":"Leti",
"stat.techia.interact_with_box":"Boxes opened",
"stat.techia.interact_with_smelter":"Interactions with Smelter",
"stat.techia.interact_with_workbench":"Interactions with Workbench",
"stat.techia.items_smelted":"Items smelted",
"stat.techia.items_workbench":"Items crafted in Workbench"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B