Skip to content

Commit

Permalink
Initial port to 20w15a
Browse files Browse the repository at this point in the history
  • Loading branch information
Prospector committed Apr 9, 2020
1 parent dc539dc commit 748ddb4
Show file tree
Hide file tree
Showing 56 changed files with 1,444 additions and 1,366 deletions.
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
tab_width = 4

[*.gradle]
indent_style = tab

[*.java]
indent_style = tab

[*.json]
indent_style = space
indent_size = 2

[*.properties]
indent_style = space
indent_size = 2

[.editorconfig]
indent_style = space
indent_size = 4
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.2.6-SNAPSHOT'
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'maven-publish'
id 'com.matthewprenger.cursegradle' version '1.4.0'
}
Expand All @@ -11,8 +11,6 @@ archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group



dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.15.2
yarn_mappings=1.15.2+build.14
minecraft_version=20w15a
yarn_mappings=20w15a+build.1
loader_version=0.8.2+build.194

# Mod Properties
mod_version = 1.0.5
mod_version = 1.1.0-beta
maven_group = campanion
archives_base_name = campanion

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.5.1+build.294-1.15
fabric_version=0.5.9+build.319-1.16
2 changes: 1 addition & 1 deletion src/main/java/com/terraformersmc/campanion/Campanion.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.registry.Registry;

public class Campanion implements ModInitializer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.terraformersmc.campanion.advancement.criterion;

import com.terraformersmc.campanion.Campanion;
import com.terraformersmc.campanion.mixin.AccessorCriterions;
import com.terraformersmc.campanion.mixin.AccessorCriteria;
import net.minecraft.advancement.criterion.Criterion;
import net.minecraft.advancement.criterion.LocationArrivalCriterion;
import net.minecraft.util.Identifier;
Expand All @@ -12,7 +12,7 @@ public class CampanionCriteria {
public static final KilledWithStoneCriterion KILLED_WITH_STONE = register(new KilledWithStoneCriterion());

private static <T extends Criterion<?>> T register(T criterion) {
return AccessorCriterions.callRegister(criterion);
return AccessorCriteria.callRegister(criterion);
}

public static void loadClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public CountCriterion(Identifier id) {
this.id = id;
}

@Override
public Identifier getId() {
return id;
}

@Override
public CountCriterion.Conditions conditionsFromJson(JsonObject json, JsonDeserializationContext context) {
NumberRange.IntRange count = NumberRange.IntRange.fromJson(json.get("count"));
return new CountCriterion.Conditions(id, count);
Expand All @@ -45,6 +47,7 @@ public boolean matches(int count) {
return this.count.test(count);
}

@Override
public JsonElement toJson() {
JsonObject json = new JsonObject();
json.add("count", this.count.toJson());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.terraformersmc.campanion.advancement.criterion;

import com.terraformersmc.campanion.Campanion;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.terraformersmc.campanion.Campanion;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.entity.Entity;
Expand All @@ -15,10 +15,12 @@
public class KilledWithStoneCriterion extends AbstractCriterion<KilledWithStoneCriterion.Conditions> {
public static final Identifier ID = new Identifier(Campanion.MOD_ID, "killed_with_stone");

@Override
public Identifier getId() {
return ID;
}

@Override
public KilledWithStoneCriterion.Conditions conditionsFromJson(JsonObject json, JsonDeserializationContext context) {
return new KilledWithStoneCriterion.Conditions(EntityPredicate.fromJson(json.get("entity")), NumberRange.IntRange.fromJson(json.get("skips")));
}
Expand All @@ -45,9 +47,10 @@ public boolean matches(ServerPlayerEntity player, Entity entity, int count) {
return this.skips.test(count) && this.entity.test(player, entity);
}

@Override
public JsonElement toJson() {
JsonObject json = new JsonObject();
json.add("entity", this.entity.serialize());
json.add("entity", this.entity.toJson());
json.add("skips", this.skips.toJson());
return json;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityContext;
import net.minecraft.block.ShapeContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
Expand All @@ -17,56 +17,61 @@

public abstract class BaseTent4WayBlock extends BaseTentBlock {

protected static final DirectionProperty FACING = Properties.HORIZONTAL_FACING;
protected static final DirectionProperty FACING = Properties.HORIZONTAL_FACING;

private final VoxelShape northShape;
private final VoxelShape eastShape;
private final VoxelShape southShape;
private final VoxelShape westShape;
private final VoxelShape northShape;
private final VoxelShape eastShape;
private final VoxelShape southShape;
private final VoxelShape westShape;

public BaseTent4WayBlock(Settings settings, DyeColor color, Direction baseDir) {
super(settings, color);
public BaseTent4WayBlock(Settings settings, DyeColor color, Direction baseDir) {
super(settings, color);

VoxelShape shape = this.createShape();
VoxelShape shape = this.createShape();

this.northShape = rotateShape(baseDir, Direction.NORTH, shape);
this.eastShape = rotateShape(baseDir, Direction.EAST, shape);
this.southShape = rotateShape(baseDir, Direction.SOUTH, shape);
this.westShape = rotateShape(baseDir, Direction.WEST, shape);
this.northShape = rotateShape(baseDir, Direction.NORTH, shape);
this.eastShape = rotateShape(baseDir, Direction.EAST, shape);
this.southShape = rotateShape(baseDir, Direction.SOUTH, shape);
this.westShape = rotateShape(baseDir, Direction.WEST, shape);

this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
}
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite());
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite());
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) {
switch (state.get(FACING)) {
case NORTH: return this.northShape;
case EAST: return this.eastShape;
case SOUTH: return this.southShape;
case WEST: return this.westShape;
default: return super.getOutlineShape(state, view, pos, context);
}
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
switch (state.get(FACING)) {
case NORTH:
return this.northShape;
case EAST:
return this.eastShape;
case SOUTH:
return this.southShape;
case WEST:
return this.westShape;
default:
return super.getOutlineShape(state, view, pos, context);
}
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}

@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}

@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}

protected abstract VoxelShape createShape();
protected abstract VoxelShape createShape();
}
48 changes: 23 additions & 25 deletions src/main/java/com/terraformersmc/campanion/block/BaseTentBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import com.terraformersmc.campanion.blockentity.TentPartBlockEntity;
import com.terraformersmc.campanion.item.CampanionItems;
import com.terraformersmc.campanion.item.TentBagItem;
import net.minecraft.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.DyeItem;
Expand Down Expand Up @@ -37,7 +40,7 @@ public class BaseTentBlock extends Block implements BlockEntityProvider {
public BaseTentBlock(Settings settings, DyeColor color) {
super(settings);
this.color = color;
if(this.color != null) {
if (this.color != null) {
TENT_PART_COLOR_MAP.computeIfAbsent(this.getClass(), aClass -> new HashMap<>()).put(this.color, this.getDefaultState());
}
}
Expand All @@ -47,27 +50,22 @@ public boolean isTranslucent(BlockState state, BlockView view, BlockPos pos) {
return true;
}

@Override
public boolean isSimpleFullBlock(BlockState state, BlockView view, BlockPos pos) {
return false;
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
BlockEntity blockEntity = world.getBlockEntity(pos);
ItemStack stack = player.getStackInHand(hand);
if(!world.isClient && stack.getItem() instanceof DyeItem && blockEntity instanceof TentPartBlockEntity && this.color != null) {
if (!world.isClient && stack.getItem() instanceof DyeItem && blockEntity instanceof TentPartBlockEntity && this.color != null) {
DyeColor stackColor = ((DyeItem) stack.getItem()).getColor();
TentPartBlockEntity tentPart = (TentPartBlockEntity) blockEntity;

Vec3d changeSize = new Vec3d(tentPart.getSize()).add(-1, -1, -1).multiply(1/2F);
Vec3d changeSize = Vec3d.method_24954(tentPart.getSize()).add(-1, -1, -1).multiply(1 / 2F);

for (int x = MathHelper.floor(-changeSize.x); x <= MathHelper.floor(changeSize.x); x++) {
for (int y = 0; y <= 2 * changeSize.getY(); y++) {
for (int z = MathHelper.floor(-changeSize.z); z <= MathHelper.floor(changeSize.z); z++) {
BlockPos off = tentPart.getLinkedPos().add(x, y, z);
BlockState offState = world.getBlockState(off);
if(offState.getBlock() instanceof BaseTentBlock && TENT_PART_COLOR_MAP.containsKey(offState.getBlock().getClass())) {
if (offState.getBlock() instanceof BaseTentBlock && TENT_PART_COLOR_MAP.containsKey(offState.getBlock().getClass())) {
BlockState newState = TENT_PART_COLOR_MAP.get(offState.getBlock().getClass()).get(stackColor);
for (Property property : newState.getProperties()) {
newState = newState.with(property, offState.get(property));
Expand All @@ -83,7 +81,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt

@Override
public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if(state.getBlock().getClass() == newState.getBlock().getClass()) {
if (state.getBlock().getClass() == newState.getBlock().getClass()) {
return;
}
super.onBlockRemoved(state, world, pos, newState, moved);
Expand All @@ -92,32 +90,32 @@ public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockSta
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
int slotIndex = -1;
for (int i = 0; i < player.inventory.getInvSize(); i++) {
ItemStack stack = player.inventory.getInvStack(i);
for (int i = 0; i < player.inventory.size(); i++) {
ItemStack stack = player.inventory.getStack(i);
if (stack.getItem() == CampanionItems.TENT_BAG && !TentBagItem.hasBlocks(stack)) {
slotIndex = i;
}
}
BlockEntity be = world.getBlockEntity(pos);
if(slotIndex != -1 && be instanceof TentPartBlockEntity) {
if (slotIndex != -1 && be instanceof TentPartBlockEntity) {
TentPartBlockEntity tentPart = (TentPartBlockEntity) be;

Vec3d changeSize = new Vec3d(tentPart.getSize()).add(-1, -1, -1).multiply(1/2F);
Vec3d changeSize = Vec3d.method_24954(tentPart.getSize()).add(-1, -1, -1).multiply(1 / 2F);

ItemStack out = new ItemStack(CampanionItems.TENT_BAG);
ListTag list = new ListTag();
for (int x = MathHelper.floor(-changeSize.x); x <= MathHelper.floor(changeSize.x); x++) {
for (int y = 0; y <= 2*changeSize.getY(); y++) {
for (int y = 0; y <= 2 * changeSize.getY(); y++) {
for (int z = MathHelper.floor(-changeSize.z); z <= MathHelper.floor(changeSize.z); z++) {
BlockPos off = tentPart.getLinkedPos().add(x, y, z);
if(world.isAir(off)) {
if (world.isAir(off)) {
continue;
}
CompoundTag tag = new CompoundTag();
tag.put("Pos", NbtHelper.fromBlockPos(new BlockPos(x, y, z)));
tag.put("BlockState", NbtHelper.fromBlockState(world.getBlockState(off)));
BlockEntity entity = world.getBlockEntity(off);
if(entity != null) {
if (entity != null) {
tag.put("BlockEntityData", entity.toTag(new CompoundTag()));
}
list.add(tag);
Expand All @@ -130,7 +128,7 @@ public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity pl
out.getOrCreateTag().put("TentSize", NbtHelper.fromBlockPos(tentPart.getSize()));


player.inventory.setInvStack(slotIndex, out);
player.inventory.setStack(slotIndex, out);
}

super.onBreak(world, pos, state, player);
Expand All @@ -145,21 +143,21 @@ public BlockEntity createBlockEntity(BlockView view) {
public static VoxelShape createDiagonals(int heightStart, int lengthStart, boolean bothSides) {
double size = 2D;
VoxelShape shape = VoxelShapes.empty();
for (double d = 0; d < heightStart; d+= size) {
shape = VoxelShapes.union(shape, createCuboidShape(0, heightStart-d-size, lengthStart-d-size, 16, heightStart-d+size, lengthStart-d+size));
if(bothSides) {
shape = VoxelShapes.union(shape, createCuboidShape(0, heightStart-d-size, lengthStart+d-size, 16, heightStart-d+size, lengthStart+d+size));
for (double d = 0; d < heightStart; d += size) {
shape = VoxelShapes.union(shape, createCuboidShape(0, heightStart - d - size, lengthStart - d - size, 16, heightStart - d + size, lengthStart - d + size));
if (bothSides) {
shape = VoxelShapes.union(shape, createCuboidShape(0, heightStart - d - size, lengthStart + d - size, 16, heightStart - d + size, lengthStart + d + size));
}
}
return shape;
}

public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
VoxelShape[] buffer = new VoxelShape[]{shape, VoxelShapes.empty()};

int times = (to.getHorizontal() - from.getHorizontal() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
}
Expand Down
Loading

0 comments on commit 748ddb4

Please sign in to comment.